From c472bf6b08032305e3cd36433cdd003e5d08acfc Mon Sep 17 00:00:00 2001 From: factosea <285808407@qq.com> Date: Thu, 14 Mar 2024 19:00:31 +0800 Subject: [PATCH 1/9] feat: tag supported with group/partition --- source/libs/parser/src/parTranslater.c | 51 ++++++++++++++------ tests/develop-test/2-query/pseudo_column.py | 8 +-- tests/system-test/2-query/count.py | 2 + tests/system-test/2-query/csum.py | 2 +- tests/system-test/2-query/group_partition.py | 6 +++ 5 files changed, 48 insertions(+), 21 deletions(-) diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 38737d7a17..6e34ab1b3b 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -2688,6 +2688,20 @@ static EDealRes rewriteExprToGroupKeyFunc(STranslateContext* pCxt, SNode** pNode return (TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_IGNORE_CHILD : DEAL_RES_ERROR); } +static bool isTbnameFuction(SNode* pNode) { + return QUERY_NODE_FUNCTION == nodeType(pNode) && FUNCTION_TYPE_TBNAME == ((SFunctionNode*)pNode)->funcType; +} + +static bool hasTbnameFunction(SNodeList* pPartitionByList) { + SNode* pPartKey = NULL; + FOREACH(pPartKey, pPartitionByList) { + if (isTbnameFuction(pPartKey)) { + return true; + } + } + return false; +} + static EDealRes doCheckExprForGroupBy(SNode** pNode, void* pContext) { STranslateContext* pCxt = (STranslateContext*)pContext; SSelectStmt* pSelect = (SSelectStmt*)pCxt->pCurrStmt; @@ -2699,15 +2713,25 @@ static EDealRes doCheckExprForGroupBy(SNode** pNode, void* pContext) { } SNode* pGroupNode = NULL; FOREACH(pGroupNode, getGroupByList(pCxt)) { - if (nodesEqualNode(getGroupByNode(pGroupNode), *pNode)) { + SNode* pActualNode = getGroupByNode(pGroupNode); + if (nodesEqualNode(pActualNode, *pNode)) { return DEAL_RES_IGNORE_CHILD; } + if (isTbnameFuction(pActualNode) && QUERY_NODE_COLUMN == nodeType(*pNode) && + ((SColumnNode*)*pNode)->colType == COLUMN_TYPE_TAG) { + return rewriteExprToGroupKeyFunc(pCxt, pNode); + } } SNode* pPartKey = NULL; + bool partionByTbname = hasTbnameFunction(pSelect->pPartitionByList); FOREACH(pPartKey, pSelect->pPartitionByList) { if (nodesEqualNode(pPartKey, *pNode)) { return rewriteExprToGroupKeyFunc(pCxt, pNode); } + if ((partionByTbname) && QUERY_NODE_COLUMN == nodeType(*pNode) && + ((SColumnNode*)*pNode)->colType == COLUMN_TYPE_TAG) { + return rewriteExprToGroupKeyFunc(pCxt, pNode); + } } if (NULL != pSelect->pWindow && QUERY_NODE_STATE_WINDOW == nodeType(pSelect->pWindow)) { if (nodesEqualNode(((SStateWindowNode*)pSelect->pWindow)->pExpr, *pNode)) { @@ -2771,10 +2795,15 @@ static EDealRes doCheckAggColCoexist(SNode** pNode, void* pContext) { return DEAL_RES_IGNORE_CHILD; } SNode* pPartKey = NULL; + bool partionByTbname = hasTbnameFunction(((SSelectStmt*)pCxt->pTranslateCxt->pCurrStmt)->pPartitionByList); FOREACH(pPartKey, ((SSelectStmt*)pCxt->pTranslateCxt->pCurrStmt)->pPartitionByList) { if (nodesEqualNode(pPartKey, *pNode)) { return rewriteExprToGroupKeyFunc(pCxt->pTranslateCxt, pNode); } + if (partionByTbname && QUERY_NODE_COLUMN == nodeType(*pNode) && + ((SColumnNode*)*pNode)->colType == COLUMN_TYPE_TAG) { + return rewriteExprToGroupKeyFunc(pCxt->pTranslateCxt, pNode); + } } if (isScanPseudoColumnFunc(*pNode) || QUERY_NODE_COLUMN == nodeType(*pNode)) { pCxt->existCol = true; @@ -3946,22 +3975,12 @@ static int32_t checkStateExpr(STranslateContext* pCxt, SNode* pNode) { return TSDB_CODE_SUCCESS; } -static bool hasPartitionByTbname(SNodeList* pPartitionByList) { - SNode* pPartKey = NULL; - FOREACH(pPartKey, pPartitionByList) { - if (QUERY_NODE_FUNCTION == nodeType(pPartKey) && FUNCTION_TYPE_TBNAME == ((SFunctionNode*)pPartKey)->funcType) { - return true; - } - } - return false; -} - static int32_t checkStateWindowForStream(STranslateContext* pCxt, SSelectStmt* pSelect) { if (!pCxt->createStream) { return TSDB_CODE_SUCCESS; } if (TSDB_SUPER_TABLE == ((SRealTableNode*)pSelect->pFromTable)->pMeta->tableType && - !hasPartitionByTbname(pSelect->pPartitionByList)) { + !hasTbnameFunction(pSelect->pPartitionByList)) { return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY, "Unsupported stream query"); } return TSDB_CODE_SUCCESS; @@ -7539,12 +7558,12 @@ static int32_t translateKillTransaction(STranslateContext* pCxt, SKillStmt* pStm static bool crossTableWithoutAggOper(SSelectStmt* pSelect) { return NULL == pSelect->pWindow && !pSelect->hasAggFuncs && !pSelect->hasIndefiniteRowsFunc && !pSelect->hasInterpFunc && TSDB_SUPER_TABLE == ((SRealTableNode*)pSelect->pFromTable)->pMeta->tableType && - !hasPartitionByTbname(pSelect->pPartitionByList); + !hasTbnameFunction(pSelect->pPartitionByList); } static bool crossTableWithUdaf(SSelectStmt* pSelect) { return pSelect->hasUdaf && TSDB_SUPER_TABLE == ((SRealTableNode*)pSelect->pFromTable)->pMeta->tableType && - !hasPartitionByTbname(pSelect->pPartitionByList); + !hasTbnameFunction(pSelect->pPartitionByList); } static int32_t checkCreateStream(STranslateContext* pCxt, SCreateStreamStmt* pStmt) { @@ -7802,7 +7821,7 @@ static int32_t checkStreamQuery(STranslateContext* pCxt, SCreateStreamStmt* pStm SSelectStmt* pSelect = (SSelectStmt*)pStmt->pQuery; if ( (SRealTableNode*)pSelect->pFromTable && ((SRealTableNode*)pSelect->pFromTable)->pMeta && TSDB_SUPER_TABLE == ((SRealTableNode*)pSelect->pFromTable)->pMeta->tableType - && !hasPartitionByTbname(pSelect->pPartitionByList) + && !hasTbnameFunction(pSelect->pPartitionByList) && pSelect->pWindow != NULL && pSelect->pWindow->type == QUERY_NODE_EVENT_WINDOW) { return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY, "Event window for stream on super table must patitioned by table name"); @@ -7830,7 +7849,7 @@ static int32_t checkStreamQuery(STranslateContext* pCxt, SCreateStreamStmt* pStm if (pSelect->pWindow != NULL && pSelect->pWindow->type == QUERY_NODE_COUNT_WINDOW) { if ( (SRealTableNode*)pSelect->pFromTable && ((SRealTableNode*)pSelect->pFromTable)->pMeta && TSDB_SUPER_TABLE == ((SRealTableNode*)pSelect->pFromTable)->pMeta->tableType - && !hasPartitionByTbname(pSelect->pPartitionByList) ) { + && !hasTbnameFunction(pSelect->pPartitionByList) ) { return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY, "Count window for stream on super table must patitioned by table name"); } diff --git a/tests/develop-test/2-query/pseudo_column.py b/tests/develop-test/2-query/pseudo_column.py index 1d94df4cff..61ea53433f 100644 --- a/tests/develop-test/2-query/pseudo_column.py +++ b/tests/develop-test/2-query/pseudo_column.py @@ -66,10 +66,10 @@ class TDTestCase: tdSql.query('select * from (select tbname, avg(f) from st partition by tbname) a partition by a.tbname order by a.tbname'); tdSql.checkRows(2) tdSql.checkCols(2) - tdSql.checkData(0, 0, 'ct1'); - tdSql.checkData(0, 1, 6.0); - tdSql.checkData(1, 0, 'ct2'); - tdSql.checkData(1, 1, 12.0); + tdSql.checkData(0, 0, 'ct1') + tdSql.checkData(0, 1, 6.0) + tdSql.checkData(1, 0, 'ct2') + tdSql.checkData(1, 1, 12.0) tdSql.error('select tbname from (select * from st)') tdSql.error('select st.tbname from (select st.tbname from st)') diff --git a/tests/system-test/2-query/count.py b/tests/system-test/2-query/count.py index c06ee28d02..f94e9eac00 100644 --- a/tests/system-test/2-query/count.py +++ b/tests/system-test/2-query/count.py @@ -103,6 +103,8 @@ class TDTestCase: tdSql.checkRows(row) tdSql.query(f'select {function_name}(c1),sum(c1) from {self.stbname} partition by tbname') tdSql.checkRows(row) + tdSql.query(f'select t0, {function_name}(c1),sum(c1) from {self.stbname} partition by tbname') + tdSql.checkRows(row) tdSql.query(f'select {function_name}(c1),sum(c1) from {self.stbname} partition by c1') tdSql.checkRows(0) tdSql.query(f'select {function_name}(c1),sum(c1) from {self.stbname} partition by t0') diff --git a/tests/system-test/2-query/csum.py b/tests/system-test/2-query/csum.py index b16f511491..f5e7456049 100644 --- a/tests/system-test/2-query/csum.py +++ b/tests/system-test/2-query/csum.py @@ -470,7 +470,7 @@ class TDTestCase: tdSql.checkRows(40) # bug need fix - tdSql.query("select tbname , csum(c1), csum(c12) from db.stb1 partition by tbname") + tdSql.query("select tbname , st1, csum(c1), csum(c12) from db.stb1 partition by tbname") tdSql.checkRows(40) tdSql.query("select tbname , csum(st1) from db.stb1 partition by tbname") tdSql.checkRows(70) diff --git a/tests/system-test/2-query/group_partition.py b/tests/system-test/2-query/group_partition.py index a20b124c33..2d206ce228 100644 --- a/tests/system-test/2-query/group_partition.py +++ b/tests/system-test/2-query/group_partition.py @@ -100,6 +100,12 @@ class TDTestCase: tdSql.query(f"select t2, t3, tbname, count(*) from {self.dbname}.{self.stable} partition by t2, t3, tbname") tdSql.checkRows(check_num) + tdSql.query(f"select t2, t3, tbname, count(*) from {self.dbname}.{self.stable} group by tbname") + tdSql.checkRows(check_num) + + tdSql.query(f"select t2, t3, tbname, count(*) from {self.dbname}.{self.stable} partition by tbname") + tdSql.checkRows(check_num) + # multi tag + col tdSql.query(f"select t1, t2, c1, count(*) from {self.dbname}.{self.stable} partition by t1, t2, c1 ") tdSql.checkRows(nonempty_tb_num * self.row_nums) From 1d1770ecca3a5f5530ff2c316b74552a996f45c4 Mon Sep 17 00:00:00 2001 From: factosea <285808407@qq.com> Date: Fri, 15 Mar 2024 09:09:51 +0800 Subject: [PATCH 2/9] fix: test case --- tests/script/tsim/parser/select_with_tags.sim | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/script/tsim/parser/select_with_tags.sim b/tests/script/tsim/parser/select_with_tags.sim index 0e777de7e8..0cc8a7db8a 100644 --- a/tests/script/tsim/parser/select_with_tags.sim +++ b/tests/script/tsim/parser/select_with_tags.sim @@ -870,7 +870,7 @@ sql_error select stddev(c2), tbname from select_tags_mt0; sql_error select twa(c2), tbname from select_tags_mt0; sql_error select interp(c2), tbname from select_tags_mt0 where ts=100001; -sql_error select t1,t2,tbname from select_tags_mt0 group by tbname; + sql select count(tbname) from select_tags_mt0 interval(1d); sql select count(tbname) from select_tags_mt0 group by t1; sql select count(tbname),SUM(T1) from select_tags_mt0 interval(1d); @@ -888,16 +888,16 @@ sql_error select tbname, t1 from select_tags_mt0 interval(1y); print ==================================>TD-4231 sql select t1,tbname from select_tags_mt0 where c1<0 sql select t1,tbname from select_tags_mt0 where c1<0 and tbname in ('select_tags_tb12') - sql select tbname from select_tags_mt0 where tbname in ('select_tags_tb12'); -sql_error select first(c1), last(c2), t1 from select_tags_mt0 group by tbname; -sql_error select first(c1), last(c2), tbname, t2 from select_tags_mt0 group by tbname; -sql_error select first(c1), count(*), t2, t1, tbname from select_tags_mt0 group by tbname; -#valid sql: select first(c1), t2 from select_tags_mt0 group by tbname; +sql select first(ts), tbname from select_tags_mt0 group by tbname; +sql select count(c1) from select_tags_mt0 where c1=99 group by tbname; +sql select count(*),tbname from select_tags_mt0 group by tbname -#sql select first(ts), tbname from select_tags_mt0 group by tbname; -#sql select count(c1) from select_tags_mt0 where c1=99 group by tbname; -#sql select count(*),tbname from select_tags_mt0 group by tbname +print ==================================> tag supported in group +sql select t1,t2,tbname from select_tags_mt0 group by tbname; +sql select first(c1), last(c2), t1 from select_tags_mt0 group by tbname; +sql select first(c1), last(c2), tbname, t2 from select_tags_mt0 group by tbname; +sql select first(c1), count(*), t2, t1, tbname from select_tags_mt0 group by tbname; system sh/exec.sh -n dnode1 -s stop -x SIGINT From 932fba9f340056b3abd8c8b42a22daad190c70e4 Mon Sep 17 00:00:00 2001 From: factosea <285808407@qq.com> Date: Fri, 15 Mar 2024 14:23:30 +0800 Subject: [PATCH 3/9] add test case --- tests/system-test/2-query/group_partition.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/system-test/2-query/group_partition.py b/tests/system-test/2-query/group_partition.py index 2d206ce228..50325579c4 100644 --- a/tests/system-test/2-query/group_partition.py +++ b/tests/system-test/2-query/group_partition.py @@ -100,11 +100,18 @@ class TDTestCase: tdSql.query(f"select t2, t3, tbname, count(*) from {self.dbname}.{self.stable} partition by t2, t3, tbname") tdSql.checkRows(check_num) - tdSql.query(f"select t2, t3, tbname, count(*) from {self.dbname}.{self.stable} group by tbname") + tdSql.query(f"select t2, t3, tbname, count(*) from {self.dbname}.{self.stable} group by tbname order by tbname asc") tdSql.checkRows(check_num) + tdSql.checkData(0, 0, 0) + tdSql.checkData(1, 0, 1) + tdSql.checkData(2, 1, 20) + tdSql.checkData(3, 1, 30) - tdSql.query(f"select t2, t3, tbname, count(*) from {self.dbname}.{self.stable} partition by tbname") + tdSql.query(f"select t2, t3, tbname, count(*) from {self.dbname}.{self.stable} partition by tbname order by tbname asc") tdSql.checkRows(check_num) + tdSql.checkData(0, 0, 0) + tdSql.checkData(2, 1, 20) + tdSql.checkData(3, 1, 30) # multi tag + col tdSql.query(f"select t1, t2, c1, count(*) from {self.dbname}.{self.stable} partition by t1, t2, c1 ") From 61e7ae53c84195bfc69b4edbdf303dd2f377d0d8 Mon Sep 17 00:00:00 2001 From: factosea <285808407@qq.com> Date: Mon, 25 Mar 2024 21:23:27 +0800 Subject: [PATCH 4/9] fix: tag supported when count on subtable --- tests/system-test/2-query/group_partition.py | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/system-test/2-query/group_partition.py b/tests/system-test/2-query/group_partition.py index 50325579c4..73be70defa 100644 --- a/tests/system-test/2-query/group_partition.py +++ b/tests/system-test/2-query/group_partition.py @@ -91,6 +91,25 @@ class TDTestCase: tdSql.query(f"select t2, t3, c1, count(*) from {self.dbname}.{self.stable} {keyword} by t2, t3, c1 ") tdSql.checkRows(nonempty_tb_num * self.row_nums) + def test_groupby_sub_table(self): + for i in range(self.tb_nums): + tbname = f"{self.dbname}.sub_{self.stable}_{i}" + ts = self.ts + i*10000 + tdSql.query(f"select t1, t2, t3,count(*) from {tbname}") + tdSql.checkRows(1) + tdSql.checkData(0, 1, i) + tdSql.checkData(0, 2, i*10) + + tdSql.query(f"select t1, t2, t3, count(*) from {tbname} group by tbname") + tdSql.checkRows(1) + tdSql.checkData(0, 1, i) + tdSql.checkData(0, 2, i*10) + + tdSql.query(f"select t1, t2, t3, count(*) from {tbname} partition by tbname") + tdSql.checkRows(1) + tdSql.checkData(0, 1, i) + tdSql.checkData(0, 2, i*10) + def test_multi_group_key(self, check_num, nonempty_tb_num): # multi tag/tbname @@ -235,12 +254,14 @@ class TDTestCase: self.test_groupby('group', self.tb_nums, nonempty_tb_num) self.test_groupby('partition', self.tb_nums, nonempty_tb_num) + self.test_groupby_sub_table() self.test_innerSelect(self.tb_nums) self.test_multi_group_key(self.tb_nums, nonempty_tb_num) self.test_multi_agg(self.tb_nums, nonempty_tb_num) self.test_window(nonempty_tb_num) self.test_event_window(nonempty_tb_num) + ## test old version before changed # self.test_groupby('group', 0, 0) # self.insert_db(5, self.row_nums) From 3257c7c08216af559cf6a7aa656719380e630d61 Mon Sep 17 00:00:00 2001 From: factosea <285808407@qq.com> Date: Mon, 1 Apr 2024 19:44:26 +0800 Subject: [PATCH 5/9] fix: tag is null when table is empty --- source/libs/executor/src/executil.c | 3 +++ source/libs/executor/src/scanoperator.c | 5 +++-- source/libs/parser/src/parTranslater.c | 22 +++++++++++++++++----- source/libs/planner/src/planLogicCreater.c | 3 +++ 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index bb89fb587b..1d58666625 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -2132,6 +2132,9 @@ int32_t buildGroupIdMapForAllTables(STableListInfo* pTableListInfo, SReadHandle* } pTableListInfo->oneTableForEachGroup = groupByTbname; + if (numOfTables == 1 && pTableListInfo->idInfo.tableType == TSDB_CHILD_TABLE) { + pTableListInfo->oneTableForEachGroup = true; + } if (groupSort && groupByTbname) { taosArraySort(pTableListInfo->pTableList, orderbyGroupIdComparFn); diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 51edfcb42c..49006186bb 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -889,14 +889,15 @@ static SSDataBlock* doGroupedTableScan(SOperatorInfo* pOperator) { if (pTableScanInfo->countState < TABLE_COUNT_STATE_END) { STableListInfo* pTableListInfo = pTableScanInfo->base.pTableListInfo; - if (pTableListInfo->oneTableForEachGroup || pTableListInfo->groupOffset) { // group by tbname, group by tag + sort + if (pTableListInfo->oneTableForEachGroup || pTableListInfo->groupOffset) { // group by tbname, group by tag + sort if (pTableScanInfo->countState < TABLE_COUNT_STATE_PROCESSED) { pTableScanInfo->countState = TABLE_COUNT_STATE_PROCESSED; STableKeyInfo* pStart = (STableKeyInfo*)tableListGetInfo(pTableScanInfo->base.pTableListInfo, pTableScanInfo->tableStartIndex); + if (NULL == pStart) return NULL; return getBlockForEmptyTable(pOperator, pStart); } - } else { // group by tag + no sort + } else { // group by tag + no sort int32_t numOfTables = tableListGetSize(pTableListInfo); if (pTableScanInfo->tableEndIndex + 1 >= numOfTables) { // get empty group, mark processed & rm from hash diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 6e34ab1b3b..72cc2df632 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -2702,6 +2702,15 @@ static bool hasTbnameFunction(SNodeList* pPartitionByList) { return false; } +static bool fromSubtable(SNode* table) { + if (NULL == table) return false; + if (table->type == QUERY_NODE_REAL_TABLE && ((SRealTableNode*)table)->pMeta && + ((SRealTableNode*)table)->pMeta->tableType == TSDB_CHILD_TABLE) { + return true; + } + return false; +} + static EDealRes doCheckExprForGroupBy(SNode** pNode, void* pContext) { STranslateContext* pCxt = (STranslateContext*)pContext; SSelectStmt* pSelect = (SSelectStmt*)pCxt->pCurrStmt; @@ -2795,15 +2804,18 @@ static EDealRes doCheckAggColCoexist(SNode** pNode, void* pContext) { return DEAL_RES_IGNORE_CHILD; } SNode* pPartKey = NULL; - bool partionByTbname = hasTbnameFunction(((SSelectStmt*)pCxt->pTranslateCxt->pCurrStmt)->pPartitionByList); + bool partionByTbname = false; + if (fromSubtable(((SSelectStmt*)pCxt->pTranslateCxt->pCurrStmt)->pFromTable) || + hasTbnameFunction(((SSelectStmt*)pCxt->pTranslateCxt->pCurrStmt)->pPartitionByList)) { + partionByTbname = true; + } FOREACH(pPartKey, ((SSelectStmt*)pCxt->pTranslateCxt->pCurrStmt)->pPartitionByList) { if (nodesEqualNode(pPartKey, *pNode)) { return rewriteExprToGroupKeyFunc(pCxt->pTranslateCxt, pNode); } - if (partionByTbname && QUERY_NODE_COLUMN == nodeType(*pNode) && - ((SColumnNode*)*pNode)->colType == COLUMN_TYPE_TAG) { - return rewriteExprToGroupKeyFunc(pCxt->pTranslateCxt, pNode); - } + } + if (partionByTbname && QUERY_NODE_COLUMN == nodeType(*pNode) && ((SColumnNode*)*pNode)->colType == COLUMN_TYPE_TAG) { + return rewriteExprToGroupKeyFunc(pCxt->pTranslateCxt, pNode); } if (isScanPseudoColumnFunc(*pNode) || QUERY_NODE_COLUMN == nodeType(*pNode)) { pCxt->existCol = true; diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index c34d8ac64f..7ce623e788 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -494,6 +494,9 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect } else if (pSelect->pPartitionByList) { isCountByTag = !keysHasCol(pSelect->pPartitionByList); } + if (pScan->tableType == TSDB_CHILD_TABLE) { + isCountByTag = true; + } } pScan->isCountByTag = isCountByTag; From f95c57695fbe5f465890e4041c60dedaab6fd279 Mon Sep 17 00:00:00 2001 From: factosea <285808407@qq.com> Date: Wed, 3 Apr 2024 13:56:52 +0800 Subject: [PATCH 6/9] add test case --- tests/system-test/2-query/count.py | 2 ++ tests/system-test/2-query/csum.py | 2 ++ tests/system-test/2-query/group_partition.py | 13 ++++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/system-test/2-query/count.py b/tests/system-test/2-query/count.py index f94e9eac00..6d34dde791 100644 --- a/tests/system-test/2-query/count.py +++ b/tests/system-test/2-query/count.py @@ -105,6 +105,8 @@ class TDTestCase: tdSql.checkRows(row) tdSql.query(f'select t0, {function_name}(c1),sum(c1) from {self.stbname} partition by tbname') tdSql.checkRows(row) + tdSql.query(f'select cast(t0 as binary(12)), {function_name}(c1),sum(c1) from {self.stbname} partition by tbname') + tdSql.checkRows(row) tdSql.query(f'select {function_name}(c1),sum(c1) from {self.stbname} partition by c1') tdSql.checkRows(0) tdSql.query(f'select {function_name}(c1),sum(c1) from {self.stbname} partition by t0') diff --git a/tests/system-test/2-query/csum.py b/tests/system-test/2-query/csum.py index f5e7456049..e3ac529d5e 100644 --- a/tests/system-test/2-query/csum.py +++ b/tests/system-test/2-query/csum.py @@ -472,6 +472,8 @@ class TDTestCase: # bug need fix tdSql.query("select tbname , st1, csum(c1), csum(c12) from db.stb1 partition by tbname") tdSql.checkRows(40) + tdSql.query("select tbname , cast(st1 as binary(24)), csum(c1), csum(c12) from db.stb1 partition by tbname") + tdSql.checkRows(40) tdSql.query("select tbname , csum(st1) from db.stb1 partition by tbname") tdSql.checkRows(70) tdSql.query("select tbname , csum(st1) from db.stb1 partition by tbname slimit 1") diff --git a/tests/system-test/2-query/group_partition.py b/tests/system-test/2-query/group_partition.py index 73be70defa..7c5f110cc9 100644 --- a/tests/system-test/2-query/group_partition.py +++ b/tests/system-test/2-query/group_partition.py @@ -100,11 +100,19 @@ class TDTestCase: tdSql.checkData(0, 1, i) tdSql.checkData(0, 2, i*10) + tdSql.query(f"select cast(t2 as binary(12)),count(*) from {tbname}") + tdSql.checkRows(1) + tdSql.checkData(0, 0, i) + + tdSql.query(f"select t2 + 1, count(*) from {tbname}") + tdSql.checkRows(1) + tdSql.checkData(0, 0, i + 1) + tdSql.query(f"select t1, t2, t3, count(*) from {tbname} group by tbname") tdSql.checkRows(1) tdSql.checkData(0, 1, i) tdSql.checkData(0, 2, i*10) - + tdSql.query(f"select t1, t2, t3, count(*) from {tbname} partition by tbname") tdSql.checkRows(1) tdSql.checkData(0, 1, i) @@ -116,6 +124,9 @@ class TDTestCase: tdSql.query(f"select t2, t3, tbname, count(*) from {self.dbname}.{self.stable} group by t2, t3, tbname") tdSql.checkRows(check_num) + tdSql.query(f"select cast(t2 as binary(12)), count(*) from {self.dbname}.{self.stable} group by t2, t3, tbname") + tdSql.checkRows(check_num) + tdSql.query(f"select t2, t3, tbname, count(*) from {self.dbname}.{self.stable} partition by t2, t3, tbname") tdSql.checkRows(check_num) From 8c34d14a9bf26ecb5775a3666f1ded313ed686ce Mon Sep 17 00:00:00 2001 From: factosea <285808407@qq.com> Date: Wed, 3 Apr 2024 17:26:51 +0800 Subject: [PATCH 7/9] fix test case --- tests/script/tsim/query/count_spread.sim | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/script/tsim/query/count_spread.sim b/tests/script/tsim/query/count_spread.sim index c03783b7fe..082b32d1fb 100644 --- a/tests/script/tsim/query/count_spread.sim +++ b/tests/script/tsim/query/count_spread.sim @@ -3,15 +3,24 @@ system sh/deploy.sh -n dnode1 -i 1 system sh/exec.sh -n dnode1 -s start sql connect -sql create database test; +sql create database test KEEP 36500; sql use test; sql create table st(ts timestamp, f int) tags(t int); -sql insert into ct1 using st tags(1) values(now, 0)(now+1s, 1)(now+2s, 10)(now+3s, 11) -sql insert into ct2 using st tags(2) values(now+2s, 2)(now+3s, 3) -sql insert into ct3 using st tags(3) values(now+4s, 4)(now+5s, 5) -sql insert into ct4 using st tags(4) values(now+6s, 6)(now+7s, 7) -sql select count(*), spread(ts) from st where tbname='ct1' +$ms = 1712135244502 +$ms1 = $ms + 1000 +$ms2 = $ms + 2000 +$ms3 = $ms + 3000 +$ms4 = $ms + 4000 +$ms5 = $ms + 5000 +$ms6 = $ms + 6000 +$ms7 = $ms + 7000 +sql insert into ct1 using st tags(1) values($ms , 0)($ms1 , 1)($ms2 , 10)($ms3 , 11) +sql insert into ct2 using st tags(2) values($ms2 , 2)($ms3 , 3) +sql insert into ct3 using st tags(3) values($ms4 , 4)($ms5 , 5) +sql insert into ct4 using st tags(4) values($ms6 , 6)($ms7 , 7) + +sql select count(*), spread(ts) from st where tbname='ct1' print $data00, $data01 if $data00 != @4@ then return -1 From 049de874de13168daa23f20508811b0d147de644 Mon Sep 17 00:00:00 2001 From: factosea <285808407@qq.com> Date: Sun, 7 Apr 2024 14:48:54 +0800 Subject: [PATCH 8/9] test case --- tests/system-test/2-query/group_partition.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/system-test/2-query/group_partition.py b/tests/system-test/2-query/group_partition.py index 7c5f110cc9..7bd5ff7954 100644 --- a/tests/system-test/2-query/group_partition.py +++ b/tests/system-test/2-query/group_partition.py @@ -113,11 +113,24 @@ class TDTestCase: tdSql.checkData(0, 1, i) tdSql.checkData(0, 2, i*10) + tdSql.query(f"select t1, t2, t3, count(*) from {tbname} group by tbname, c1, t4") + tdSql.checkData(0, 1, i) + tdSql.checkData(0, 2, i*10) + tdSql.query(f"select t1, t2, t3, count(*) from {tbname} partition by tbname") tdSql.checkRows(1) tdSql.checkData(0, 1, i) tdSql.checkData(0, 2, i*10) + tdSql.query(f"select t1, t2, t3, count(*) from {tbname} partition by c1, tbname") + tdSql.checkData(0, 1, i) + tdSql.checkData(0, 2, i*10) + + tdSql.query(f"select t1, t2, t3, count(*) from {self.stable} partition by c1, tbname order by tbname desc") + tdSql.checkRows(50) + tdSql.checkData(0, 1, 4) + tdSql.checkData(0, 2, 40) + def test_multi_group_key(self, check_num, nonempty_tb_num): # multi tag/tbname From 30c0d944d93b56f75683e2fe27fc3c0733e80adf Mon Sep 17 00:00:00 2001 From: factosea <285808407@qq.com> Date: Sun, 7 Apr 2024 17:45:45 +0800 Subject: [PATCH 9/9] fix test case --- tests/system-test/2-query/group_partition.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system-test/2-query/group_partition.py b/tests/system-test/2-query/group_partition.py index 7bd5ff7954..7c3c0555c9 100644 --- a/tests/system-test/2-query/group_partition.py +++ b/tests/system-test/2-query/group_partition.py @@ -126,7 +126,7 @@ class TDTestCase: tdSql.checkData(0, 1, i) tdSql.checkData(0, 2, i*10) - tdSql.query(f"select t1, t2, t3, count(*) from {self.stable} partition by c1, tbname order by tbname desc") + tdSql.query(f"select t1, t2, t3, count(*) from {self.dbname}.{self.stable} partition by c1, tbname order by tbname desc") tdSql.checkRows(50) tdSql.checkData(0, 1, 4) tdSql.checkData(0, 2, 40)