From c008d7d0ad86c65a818e489a1015f0bf321d6af5 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Sat, 27 Nov 2021 20:51:44 +0800 Subject: [PATCH] [TD-10990] fix stddev empty group by json->key --- src/client/src/tscServer.c | 2 +- src/client/src/tscSubquery.c | 3 ++- src/query/inc/qTableMeta.h | 1 + tests/pytest/stable/json_tag.py | 6 +++++- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index e7876b6a7a..c80aca3a4a 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -1841,7 +1841,7 @@ int tscProcessRetrieveGlobalMergeRsp(SSqlObj *pSql) { uint64_t localQueryId = pSql->self; qTableQuery(pQueryInfo->pQInfo, &localQueryId); bool convertJson = true; - if (tscMultiRoundQuery(pQueryInfo, 0)) convertJson = false; + if (pQueryInfo->isStddev == true) convertJson = false; convertQueryResult(pRes, pQueryInfo, pSql->self, true, convertJson); code = pRes->code; diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 610128b578..1b0591c6b8 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -2450,6 +2450,7 @@ int32_t tscHandleFirstRoundStableQuery(SSqlObj *pSql) { STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pNewQueryInfo, 0); tscInitQueryInfo(pNewQueryInfo); + pNewQueryInfo->isStddev = true; // for json tag // add the group cond pNewQueryInfo->groupbyExpr = pQueryInfo->groupbyExpr; @@ -3708,7 +3709,7 @@ TAOS_ROW doSetResultRowData(SSqlObj *pSql) { int32_t type = pInfo->field.type; int32_t bytes = pInfo->field.bytes; - if (tscMultiRoundQuery(pQueryInfo, 0) && pQueryInfo->round == 0 && type == TSDB_DATA_TYPE_JSON){ // for json tag compare in the second round of stddev + if (pQueryInfo->isStddev && type == TSDB_DATA_TYPE_JSON){ // for json tag compare in the second round of stddev pRes->tsrow[j] = pRes->urow[i]; }else if (!IS_VAR_DATA_TYPE(type) && type != TSDB_DATA_TYPE_JSON) { pRes->tsrow[j] = isNull(pRes->urow[i], type) ? NULL : pRes->urow[i]; diff --git a/src/query/inc/qTableMeta.h b/src/query/inc/qTableMeta.h index 8714311781..d47189691e 100644 --- a/src/query/inc/qTableMeta.h +++ b/src/query/inc/qTableMeta.h @@ -166,6 +166,7 @@ typedef struct SQueryInfo { bool stateWindow; bool globalMerge; bool multigroupResult; + bool isStddev; } SQueryInfo; /** diff --git a/tests/pytest/stable/json_tag.py b/tests/pytest/stable/json_tag.py index 514d05c587..efabcb578d 100644 --- a/tests/pytest/stable/json_tag.py +++ b/tests/pytest/stable/json_tag.py @@ -105,7 +105,6 @@ class TDTestCase: tdSql.checkRows(0) tdSql.query("select jtag->'sex' from db_json_tag_test.jsons1 where jtag?'sex' or jtag?'num'") - tdSql.checkData(0, 0, "\"femail\"") tdSql.checkRows(3) tdSql.query("select *,tbname from db_json_tag_test.jsons1 where jtag->'location'='beijing'") @@ -290,6 +289,11 @@ class TDTestCase: tdSql.checkData(1, 2, 1) tdSql.checkData(3, 2, 11) + tdSql.query("select stddev(dataint) from db_json_tag_test.jsons1 group by jtag->'location'") + tdSql.checkData(0, 1, None) + tdSql.checkData(1, 0, 0.5) + tdSql.checkData(2, 0, 0) + # test json->'key'=null tdSql.execute("insert into db_json_tag_test.jsons1_9 values('2020-04-17 15:20:00.000', 5, false, 'json19')") tdSql.query("select * from db_json_tag_test.jsons1") -- GitLab