diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index 91db5277bf0f26cbbe897bd13f07eb4d19278681..89647324b9e88e04034c136531abc117eb497f33 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -1077,7 +1077,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC return code; } - tdAddColToKVRow(&kvRowBuilder, pSchema->colId, pSchema->type, tagVal); + tdAddColToKVRow(&kvRowBuilder, pSchema->colId, pSchema->type, tagVal, false); } // encode json tag string diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 208fa10abc8ad38bb3c68064662d7149aa88071f..180e3d7443fdda08f333363c36c4f5d1eb4864f9 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -7618,7 +7618,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4); } - tdAddColToKVRow(&kvRowBuilder, pSchema->colId, pSchema->type, tagVal); + tdAddColToKVRow(&kvRowBuilder, pSchema->colId, pSchema->type, tagVal, false); findColumnIndex = true; break; @@ -7640,7 +7640,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { SSchema* pSchema = &pTagSchema[i]; tVariantListItem* pItem = taosArrayGet(pValList, i); - char tagVal[TSDB_MAX_TAGS_LEN]; + char tagVal[TSDB_MAX_TAGS_LEN] = {0}; if (pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) { if (pItem->pVar.nLen > pSchema->bytes) { tdDestroyKVRowBuilder(&kvRowBuilder); @@ -7678,7 +7678,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4); } - tdAddColToKVRow(&kvRowBuilder, pSchema->colId, pSchema->type, tagVal); + tdAddColToKVRow(&kvRowBuilder, pSchema->colId, pSchema->type, tagVal, false); } } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index be61434dacd6660f3685303895109f40a3d66983..615183f9f3863695134dd6f706034b12987bac47 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -5178,7 +5178,7 @@ int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, in } varDataSetLen(tagVal, output); - tdAddColToKVRow(kvRowBuilder, jsonIndex++, TSDB_DATA_TYPE_NCHAR, tagVal); // add json key + tdAddColToKVRow(kvRowBuilder, jsonIndex++, TSDB_DATA_TYPE_NCHAR, tagVal, false); // add json key memset(tagVal, 0, TSDB_MAX_TAGS_LEN); if(item->type == cJSON_String){ // add json value format: type|data @@ -5192,12 +5192,12 @@ int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, in } varDataSetLen(tagData, output); - tdAddColToKVRow(kvRowBuilder, jsonIndex++, TSDB_DATA_TYPE_NCHAR, tagVal); + tdAddColToKVRow(kvRowBuilder, jsonIndex++, TSDB_DATA_TYPE_NCHAR, tagVal, true); }else if(item->type == cJSON_Number){ *tagVal = item->type; // type char* tagData = tagVal + CHAR_BYTES; *((double *)tagData) = item->valuedouble; - tdAddColToKVRow(kvRowBuilder, jsonIndex++, TSDB_DATA_TYPE_BIGINT, tagVal); + tdAddColToKVRow(kvRowBuilder, jsonIndex++, TSDB_DATA_TYPE_BIGINT, tagVal, true); }else{ retCode = tscSQLSyntaxErrMsg(errMsg, "invalidate json value", NULL); goto end; diff --git a/src/common/inc/tdataformat.h b/src/common/inc/tdataformat.h index a01c3775397e25849d9e8ff70409db7ac0af90ba..54e9521469483ca5ec0ee382827292903699e9f1 100644 --- a/src/common/inc/tdataformat.h +++ b/src/common/inc/tdataformat.h @@ -544,7 +544,7 @@ void tdDestroyKVRowBuilder(SKVRowBuilder *pBuilder); void tdResetKVRowBuilder(SKVRowBuilder *pBuilder); SKVRow tdGetKVRowFromBuilder(SKVRowBuilder *pBuilder); -static FORCE_INLINE int tdAddColToKVRow(SKVRowBuilder *pBuilder, int16_t colId, int8_t type, void *value) { +static FORCE_INLINE int tdAddColToKVRow(SKVRowBuilder *pBuilder, int16_t colId, int8_t type, void *value, bool isJumpJsonVType) { if (pBuilder->nCols >= pBuilder->tCols) { pBuilder->tCols *= 2; SColIdx* pColIdx = (SColIdx *)realloc((void *)(pBuilder->pColIdx), sizeof(SColIdx) * pBuilder->tCols); @@ -557,7 +557,9 @@ static FORCE_INLINE int tdAddColToKVRow(SKVRowBuilder *pBuilder, int16_t colId, pBuilder->nCols++; - int tlen = IS_VAR_DATA_TYPE(type) ? varDataTLen(value) : TYPE_BYTES[type]; + void *jumpType = value; + if(isJumpJsonVType) jumpType = value + CHAR_BYTES; + int tlen = IS_VAR_DATA_TYPE(type) ? varDataTLen(jumpType) : TYPE_BYTES[type]; if (tlen > pBuilder->alloc - pBuilder->size) { while (tlen > pBuilder->alloc - pBuilder->size) { pBuilder->alloc *= 2;