diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index e52f8699100918c3e66ab1e58b4a0b6d7405406a..95104bfb6303826baec2af6bc6f3618bbc5d672a 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -4420,7 +4420,7 @@ static int32_t validateLikeExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_t // check for match expression static int32_t validateJsonTagExpr(tSqlExpr* pExpr, char* msgBuf) { const char* msg1 = "not support json tag column filter"; - const char* msg2 = "tag json key is too long, exceed to 64"; + const char* msg2 = "tag json key is invalidate"; const char* msg3 = "tag json key must be string"; tSqlExpr* pLeft = pExpr->pLeft; @@ -4430,17 +4430,17 @@ static int32_t validateJsonTagExpr(tSqlExpr* pExpr, char* msgBuf) { if (pRight != NULL && !IS_VAR_DATA_TYPE(pRight->value.nType)) return invalidOperationMsg(msgBuf, msg3); - if (pRight != NULL && pRight->value.nLen >= TSDB_COL_NAME_LEN) + if (pRight != NULL && (pRight->value.nLen > TSDB_MAX_JSON_KEY_LEN || pRight->value.nLen <= 0)) return invalidOperationMsg(msgBuf, msg2); } else { - if (pLeft != NULL && pLeft->tokenId == TK_ID && pExpr->tokenId != TK_NULL) { + if (pLeft != NULL && pLeft->tokenId == TK_ID && pExpr->tokenId != TK_ISNULL && pExpr->tokenId != TK_NOTNULL) { return invalidOperationMsg(msgBuf, msg1); } if (pLeft != NULL && pLeft->tokenId == TK_ARROW) { if (pLeft->pRight && !IS_VAR_DATA_TYPE(pLeft->pRight->value.nType)) return invalidOperationMsg(msgBuf, msg3); - if (pLeft->pRight && pLeft->pRight->value.nLen >= TSDB_COL_NAME_LEN) + if (pLeft->pRight && (pLeft->pRight->value.nLen > TSDB_MAX_JSON_KEY_LEN || pLeft->pRight->value.nLen <= 0)) return invalidOperationMsg(msgBuf, msg2); } } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index caab7ed809eb9b997b3a01019b70f1e1031e3e55..3ae9a2b2446abbdea1dcb1f33988dc1d5315b26b 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -5210,7 +5210,7 @@ void parseTagValue2Dst(char* result, char* dst){ char tagJsonValue[TSDB_MAX_TAGS_LEN] = {0}; int32_t length = taosUcs4ToMbs(varDataVal(realData), varDataLen(realData), tagJsonValue); - if (length == 0) { + if (length < 0) { tscError("charset:%s to %s. val:%s convert json value failed.", DEFAULT_UNICODE_ENCODEC, tsCharset, (char*)result); return; diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index 6cb9102cfcb3d1eb05c269b3a5b303a6bda6f1ad..09899fd7eeb3746d82e818758b84dbc95b442694 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -1161,7 +1161,7 @@ int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *g if(pLeft->nodeType == TSQL_NODE_EXPR && pLeft->_node.optr == TSDB_RELATION_ARROW){ // json tag -> operation assert(info->pTable != NULL); SSchema* schema = pLeft->_node.pLeft->pSchema; - if(pLeft->_node.pRight->pVal->nLen >= TSDB_MAX_JSON_KEY_LEN) return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH; + if(pLeft->_node.pRight->pVal->nLen > TSDB_MAX_JSON_KEY_LEN) return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH; char keyMd5[TSDB_MAX_JSON_KEY_MD5_LEN] = {0}; jsonKeyMd5(pLeft->_node.pRight->pVal->pz, pLeft->_node.pRight->pVal->nLen, keyMd5); memcpy(schema->name, keyMd5, TSDB_MAX_JSON_KEY_MD5_LEN); @@ -1174,7 +1174,7 @@ int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *g pLeft = pLeft->_node.pLeft; // -> operation use left as input }else if(tree->_node.optr == TSDB_RELATION_QUESTION){ SSchema* schema = pLeft->pSchema; - if(tree->_node.pRight->pVal->nLen >= TSDB_MAX_JSON_KEY_LEN) return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH; + if(tree->_node.pRight->pVal->nLen > TSDB_MAX_JSON_KEY_LEN) return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH; char keyMd5[TSDB_MAX_JSON_KEY_MD5_LEN] = {0}; jsonKeyMd5(tree->_node.pRight->pVal->pz, tree->_node.pRight->pVal->nLen, keyMd5); memcpy(schema->name, keyMd5, TSDB_MAX_JSON_KEY_MD5_LEN); diff --git a/tests/pytest/stable/json_tag.py b/tests/pytest/stable/json_tag.py index 619df8dab62f93a5e8b02dd69e40e43dc07a0806..134fdc696078f0343dbac60958481e9cbea74e58 100644 --- a/tests/pytest/stable/json_tag.py +++ b/tests/pytest/stable/json_tag.py @@ -61,9 +61,12 @@ class TDTestCase: #tdSql.error("select * from db_json_tag_test.jsons1 where jtag->'location'=4") tdSql.error("select * from db_json_tag_test.jsons1 where jtag->location='beijing'") tdSql.error("select * from db_json_tag_test.jsons1 where jtag->'location'") + tdSql.error("select * from db_json_tag_test.jsons1 where jtag->''") + tdSql.error("select * from db_json_tag_test.jsons1 where jtag->''=9") tdSql.error("select jtag->location from db_json_tag_test.jsons1") tdSql.error("select jtag?location from db_json_tag_test.jsons1") tdSql.error("select * from db_json_tag_test.jsons1 where jtag?location") + tdSql.error("select * from db_json_tag_test.jsons1 where jtag?''") tdSql.error("select * from db_json_tag_test.jsons1 where jtag?'location'='beijing'") # test select condition @@ -170,12 +173,33 @@ class TDTestCase: tdSql.error("CREATE TABLE if not exists db_json_tag_test.jsons1_5 using db_json_tag_test.jsons1 tags('efwewf')") tdSql.error("CREATE TABLE if not exists db_json_tag_test.jsons1_5 using db_json_tag_test.jsons1 tags('\t')") tdSql.execute("CREATE TABLE if not exists db_json_tag_test.jsons1_6 using db_json_tag_test.jsons1 tags('')") + tdSql.query("select jtag from db_json_tag_test.jsons1_6") + tdSql.checkData(0, 0, "NULL") + tdSql.execute("CREATE TABLE if not exists db_json_tag_test.jsons1_7 using db_json_tag_test.jsons1 tags('{}')") + tdSql.query("select jtag from db_json_tag_test.jsons1_7") + tdSql.checkData(0, 0, "NULL") + tdSql.execute("CREATE TABLE if not exists db_json_tag_test.jsons1_8 using db_json_tag_test.jsons1 tags('null')") + tdSql.query("select jtag from db_json_tag_test.jsons1_8") + tdSql.checkData(0, 0, "NULL") + tdSql.execute("CREATE TABLE if not exists db_json_tag_test.jsons1_9 using db_json_tag_test.jsons1 tags('{\"\":4, \"time\":null}')") + tdSql.query("select jtag from db_json_tag_test.jsons1_9") + tdSql.checkData(0, 0, "NULL") + tdSql.execute("CREATE TABLE if not exists db_json_tag_test.jsons1_10 using db_json_tag_test.jsons1 tags('{\"k1\":\"\",\"k1\":\"v1\",\"k2\":true,\"k3\":false,\"k4\":55}')") - tdSql.query("select * from db_json_tag_test.jsons1 where datastr match 'json and jtag->'location' match 'jin'") - tdSql.checkRows(2) + tdSql.query("select jtag from db_json_tag_test.jsons1_10") + tdSql.checkData(0, 0, "{\"k1\":\"\",\"k2\":true,\"k3\":false,\"k4\":55}") + + tdSql.query("select jtag->'k2' from db_json_tag_test.jsons1_10") + tdSql.checkData(0, 0, "true") + + tdSql.query("select jtag from db_json_tag_test.jsons1 where jtag->'k1'=''") + tdSql.checkRows(1) + + tdSql.query("select jtag from db_json_tag_test.jsons1 where jtag->'k2'=true") + tdSql.checkRows(1) def stop(self): tdSql.close()