From 698f954b27dd7172e208b05393ce74b96efee6cc Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Thu, 30 Sep 2021 17:43:05 +0800 Subject: [PATCH] TD-6129 add tag?'key' in where logic --- src/client/src/tscLocal.c | 5 ++++- src/client/src/tscUtil.c | 4 ++-- src/query/src/qExecutor.c | 3 +-- src/util/src/tarray.c | 4 ++-- tests/pytest/stable/json_tag.py | 12 ++++++++++++ 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index 07db18b498..c1141898cd 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -89,7 +89,10 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) { STR_WITH_MAXSIZE_TO_VARSTR(dst, type, pField->bytes); int32_t bytes = pSchema[i].bytes; - if (pSchema[i].type == TSDB_DATA_TYPE_BINARY || pSchema[i].type == TSDB_DATA_TYPE_NCHAR) { + if (pSchema[i].type == TSDB_DATA_TYPE_BINARY || (pSchema[i].type == TSDB_DATA_TYPE_JSON && JSON_TYPE_BINARY)){ + bytes -= VARSTR_HEADER_SIZE; + } + else if(pSchema[i].type == TSDB_DATA_TYPE_NCHAR || (pSchema[i].type == TSDB_DATA_TYPE_JSON && JSON_TYPE_NCHAR)) { bytes -= VARSTR_HEADER_SIZE; if (pSchema[i].type == TSDB_DATA_TYPE_NCHAR) { diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index ec9bacd6a4..afb5deca88 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -5325,7 +5325,7 @@ int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, in char tagVal[TSDB_MAX_TAGS_LEN] = {0}; int32_t outLen = 0; if (JSON_TYPE_BINARY){ - strncpy(tagVal, item->string, strlen(item->string)); + strncpy(varDataVal(tagVal), item->string, strlen(item->string)); outLen = strlen(item->string); }else if(JSON_TYPE_NCHAR){ if (!taosMbsToUcs4(item->string, strlen(item->string), varDataVal(tagVal), TSDB_MAX_TAGS_LEN - VARSTR_HEADER_SIZE, &outLen)) { @@ -5344,7 +5344,7 @@ int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, in *tagVal = jsonType2DbType(0, item->type); // type char* tagData = POINTER_SHIFT(tagVal,CHAR_BYTES); if (JSON_TYPE_BINARY){ - strncpy(tagVal, item->valuestring, strlen(item->valuestring)); + strncpy(varDataVal(tagData), item->valuestring, strlen(item->valuestring)); outLen = strlen(item->valuestring); }else if(JSON_TYPE_NCHAR) { if (!taosMbsToUcs4(item->valuestring, strlen(item->valuestring), varDataVal(tagData), diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index fc4b4af1c7..91dace974b 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -7181,7 +7181,6 @@ static SSDataBlock* doTagScan(void* param, bool* newgroup) { type = pExprInfo[j].base.resType; bytes = pExprInfo[j].base.resBytes; - char* tagJsonElementData = NULL; dst = pColInfo->pData + count * pExprInfo[j].base.resBytes; if (pExprInfo[j].base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { data = tsdbGetTableName(item->pTable); @@ -7189,7 +7188,7 @@ static SSDataBlock* doTagScan(void* param, bool* newgroup) { if(type == TSDB_DATA_TYPE_JSON){ data = tsdbGetTableTagVal(item->pTable, pExprInfo[j].base.colInfo.colId, type, bytes); if(pExprInfo[j].base.numOfParams > 0){ // tag-> operation - tagJsonElementData = calloc(bytes, 1); + char* tagJsonElementData = calloc(bytes, 1); findTagValue(item->pTable, pExprInfo[j].base.param[0].pz, pExprInfo[j].base.param[0].nLen, tagJsonElementData, bytes); *dst = SELECT_ELEMENT_JSON_TAG; // select tag->element dst++; diff --git a/src/util/src/tarray.c b/src/util/src/tarray.c index 007ce06829..2fb9403683 100644 --- a/src/util/src/tarray.c +++ b/src/util/src/tarray.c @@ -281,8 +281,8 @@ void taosArrayClear(SArray* pArray) { void* taosArrayDestroy(SArray* pArray) { if (pArray) { - free(pArray->pData); - free(pArray); + tfree(pArray->pData); + tfree(pArray); } return NULL; diff --git a/tests/pytest/stable/json_tag.py b/tests/pytest/stable/json_tag.py index 0b669b548c..31517d1e47 100644 --- a/tests/pytest/stable/json_tag.py +++ b/tests/pytest/stable/json_tag.py @@ -142,6 +142,18 @@ class TDTestCase: tdSql.query("select *,tbname from db_json_tag_test.jsons1 where (jtag->'location' like 'bei%' or jtag->'num'=34) and jtag->'class'=55") tdSql.checkRows(0) + # test where condition in + tdSql.query("select * from db_json_tag_test.jsons1 where jtag->'location' in ('beijing')") + tdSql.checkRows(2) + + tdSql.query("select * from db_json_tag_test.jsons1 where jtag->'num' in (5,34)") + tdSql.checkRows(2) + + tdSql.error("select * from db_json_tag_test.jsons1 where jtag->'num' in ('5',34)") + + tdSql.query("select * from db_json_tag_test.jsons1 where jtag->'location' in ('shanghai') and jtag->'class'=55") + tdSql.checkRows(1) + def stop(self): tdSql.close() -- GitLab