From fd7f126804fb1548bfe0b24d2a5f8abdb50276a0 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Tue, 19 Oct 2021 16:35:28 +0800 Subject: [PATCH] TD-6129 fix error if json key not the same type --- src/client/src/tscSQLParser.c | 5 ++++- tests/pytest/stable/json_tag.py | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index d574fdbdef..7a22be880c 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -2322,7 +2322,10 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t if (tokenId == TK_ARROW && pSchema->type != TSDB_DATA_TYPE_JSON) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4); } - + if(pSchema->type == TSDB_DATA_TYPE_JSON && tokenId == TK_ARROW){ + pItem->aliasName = calloc(1, pItem->pNode->exprToken.n + 1); + memcpy(pItem->aliasName, pItem->pNode->exprToken.z, pItem->pNode->exprToken.n); + } addProjectQueryCol(pQueryInfo, startPos, &index, pItem, getNewResColId(pCmd)); pQueryInfo->type |= TSDB_QUERY_TYPE_PROJECTION_QUERY; } diff --git a/tests/pytest/stable/json_tag.py b/tests/pytest/stable/json_tag.py index 27be0b7eac..e48f340d59 100644 --- a/tests/pytest/stable/json_tag.py +++ b/tests/pytest/stable/json_tag.py @@ -235,7 +235,13 @@ class TDTestCase: tdSql.checkRows(3) # test chinese - tdSql.execute("CREATE TABLE if not exists db_json_tag_test.jsons1_11 using db_json_tag_test.jsons1 tags('{\"k1\":\"中国\",\"k2\":\"是是是\"}')") + tdSql.execute("CREATE TABLE if not exists db_json_tag_test.jsons1_11 using db_json_tag_test.jsons1 tags('{\"k1\":\"中国\",\"k5\":\"是是是\"}')") + + tdSql.query("select tbname,jtag from db_json_tag_test.jsons1 where jtag->'k1' match '中'") + tdSql.checkRows(1) + + tdSql.query("select tbname,jtag from db_json_tag_test.jsons1 where jtag->'k1'='中国'") + tdSql.checkRows(1) def stop(self): tdSql.close() -- GitLab