diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index 18932119ff..53197d2d7b 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -120,6 +120,7 @@ struct SColVal { uint8_t *pData; }; +#pragma pack(push, 1) struct STagVal { union { int16_t cid; @@ -135,7 +136,6 @@ struct STagVal { }; }; -#pragma pack(push, 1) #define TD_TAG_JSON ((int8_t)0x40) // distinguish JSON string and JSON value with the highest bit #define TD_TAG_LARGE ((int8_t)0x20) struct STag { diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index dead85f854..24aaeec406 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -567,14 +567,16 @@ SArray *metaGetSmaTbUids(SMeta *pMeta) { const void *metaGetTableTagVal(SMetaEntry *pEntry, int16_t type, STagVal *val) { ASSERT(pEntry->type == TSDB_CHILD_TABLE); STag *tag = (STag *)pEntry->ctbEntry.pTags; - tTagGet(tag, val); + if (type == TSDB_DATA_TYPE_JSON){ + if(tag->nTag == 0){ + return NULL; + } + return tag; + } + bool find = tTagGet(tag, val); - if(val->type == TSDB_DATA_TYPE_NULL){ + if(!find){ return NULL; } - if (type == TSDB_DATA_TYPE_JSON){ - return tag; - }else{ - return val; - } + return val; } \ No newline at end of file diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 984688fc19..5ac13d478d 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -787,10 +787,16 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) { pTagColumn = &stbEntry.stbEntry.schemaTag.pSchema[0]; - STagVal tagVal = {.cid = pTagColumn->colId}; - tTagGet((const STag *)pCtbEntry->ctbEntry.pTags, &tagVal); - pTagData = tagVal.pData; - nTagData = (int32_t)tagVal.nData; + if(pTagColumn->type != TSDB_DATA_TYPE_JSON){ + STagVal tagVal = {.cid = pTagColumn->colId}; + tTagGet((const STag *)pCtbEntry->ctbEntry.pTags, &tagVal); + pTagData = tagVal.pData; + nTagData = (int32_t)tagVal.nData; + }else{ + //pTagData = pCtbEntry->ctbEntry.pTags; + //nTagData = ((const STag *)pCtbEntry->ctbEntry.pTags)->len; + } + // update tag index #ifdef USE_INVERTED_INDEX diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 18fb5322b1..dfd89a230d 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -330,6 +330,9 @@ static bool isValidateTag(char* input) { int32_t parseJsontoTagData(const char* json, SArray* pTagVals, STag **ppTag, SMsgBuf* pMsgBuf) { int32_t retCode = TSDB_CODE_SUCCESS; + cJSON* root = NULL; + SHashObj* keyHash = NULL; + int32_t size = 0; // set json NULL data if (!json || strtrim((char*)json) == 0 || strcasecmp(json, TSDB_DATA_NULL_STR_L) == 0) { retCode = TSDB_CODE_SUCCESS; @@ -337,19 +340,19 @@ int32_t parseJsontoTagData(const char* json, SArray* pTagVals, STag **ppTag, SMs } // set json real data - cJSON* root = cJSON_Parse(json); + root = cJSON_Parse(json); if (root == NULL) { retCode = buildSyntaxErrMsg(pMsgBuf, "json parse error", json); goto end; } - int32_t size = cJSON_GetArraySize(root); + size = cJSON_GetArraySize(root); if (!cJSON_IsObject(root)) { retCode = buildSyntaxErrMsg(pMsgBuf, "json error invalide value", json); goto end; } - SHashObj* keyHash = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, false); + keyHash = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, false); for (int32_t i = 0; i < size; i++) { cJSON* item = cJSON_GetArrayItem(root, i); if (!item) {