From 1be414354d319f0fc295398a82449431e09f23c3 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Fri, 22 Jul 2022 17:06:08 +0800 Subject: [PATCH] fix: plan problem when functions that requires a timeline is used directly in a super table --- source/libs/executor/src/scanoperator.c | 10 +++++-- source/libs/function/src/builtinsimpl.c | 32 +++++++++------------ source/libs/planner/test/planPartByTest.cpp | 14 ++++++++- tests/system-test/2-query/csum.py | 2 +- 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index fc29eed455..5deaff5200 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -2895,6 +2895,7 @@ int32_t startGroupTableMergeScan(SOperatorInfo* pOperator) { int32_t tableEndIdx = pInfo->tableEndIndex; STableListInfo* tableListInfo = pInfo->tableListInfo; + pInfo->dataReaders = taosArrayInit(64, POINTER_BYTES); createMultipleDataReaders(&pInfo->cond, &pInfo->readHandle, tableListInfo, tableStartIdx, tableEndIdx, pInfo->dataReaders, GET_TASKID(pTaskInfo)); @@ -3067,7 +3068,13 @@ int32_t getTableMergeScanExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExpla int32_t compareTableKeyInfoByGid(const void* p1, const void* p2) { const STableKeyInfo* info1 = p1; const STableKeyInfo* info2 = p2; - return info1->groupId - info2->groupId; + if (info1->groupId < info2->groupId) { + return -1; + } else if (info1->groupId > info2->groupId) { + return 1; + } else { + return 0; + } } SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanNode, STableListInfo* pTableListInfo, @@ -3109,7 +3116,6 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN pInfo->pColMatchInfo = pColList; pInfo->pResBlock = createResDataBlock(pDescNode); - pInfo->dataReaders = taosArrayInit(64, POINTER_BYTES); pInfo->sortSourceParams = taosArrayInit(64, sizeof(STableMergeScanSortSourceParam)); pInfo->pSortInfo = generateSortByTsInfo(pInfo->pColMatchInfo, pInfo->cond.order); diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 05f84df7f8..bb4467cf34 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -2465,8 +2465,8 @@ bool apercentileFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResult } int32_t apercentileFunction(SqlFunctionCtx* pCtx) { - int32_t numOfElems = 0; - SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); + int32_t numOfElems = 0; + SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); SInputColumnInfoData* pInput = &pCtx->input; SColumnInfoData* pCol = pInput->pData[0]; @@ -2502,7 +2502,7 @@ int32_t apercentileFunction(SqlFunctionCtx* pCtx) { } qDebug("add %d elements into histogram, total:%d, numOfEntry:%d, %p", numOfElems, pInfo->pHisto->numOfElems, - pInfo->pHisto->numOfEntries, pInfo->pHisto); + pInfo->pHisto->numOfEntries, pInfo->pHisto); } SET_VAL(pResInfo, numOfElems, 1); @@ -2542,18 +2542,17 @@ static void apercentileTransferInfo(SAPercentileInfo* pInput, SAPercentileInfo* memcpy(pHisto, pInput->pHisto, sizeof(SHistogramInfo) + sizeof(SHistBin) * (MAX_HISTOGRAM_BIN + 1)); pHisto->elems = (SHistBin*)((char*)pHisto + sizeof(SHistogramInfo)); - qDebug("merge histo, total:%"PRId64", entry:%d, %p", pHisto->numOfElems, pHisto->numOfEntries, pHisto); + qDebug("merge histo, total:%" PRId64 ", entry:%d, %p", pHisto->numOfElems, pHisto->numOfEntries, pHisto); } else { pHisto->elems = (SHistBin*)((char*)pHisto + sizeof(SHistogramInfo)); - qDebug("input histogram, elem:%"PRId64", entry:%d, %p", pHisto->numOfElems, pHisto->numOfEntries, - pInput->pHisto); + qDebug("input histogram, elem:%" PRId64 ", entry:%d, %p", pHisto->numOfElems, pHisto->numOfEntries, + pInput->pHisto); SHistogramInfo* pRes = tHistogramMerge(pHisto, pInput->pHisto, MAX_HISTOGRAM_BIN); memcpy(pHisto, pRes, sizeof(SHistogramInfo) + sizeof(SHistBin) * MAX_HISTOGRAM_BIN); pHisto->elems = (SHistBin*)((char*)pHisto + sizeof(SHistogramInfo)); - qDebug("merge histo, total:%"PRId64", entry:%d, %p", pHisto->numOfElems, pHisto->numOfEntries, - pHisto); + qDebug("merge histo, total:%" PRId64 ", entry:%d, %p", pHisto->numOfElems, pHisto->numOfEntries, pHisto); tHistogramDestroy(&pRes); } } @@ -2580,7 +2579,8 @@ int32_t apercentileFunctionMerge(SqlFunctionCtx* pCtx) { } if (pInfo->algo != APERCT_ALGO_TDIGEST) { - qDebug("after merge, total:%d, numOfEntry:%d, %p", pInfo->pHisto->numOfElems, pInfo->pHisto->numOfEntries, pInfo->pHisto); + qDebug("after merge, total:%d, numOfEntry:%d, %p", pInfo->pHisto->numOfElems, pInfo->pHisto->numOfEntries, + pInfo->pHisto); } SET_VAL(pResInfo, 1, 1); @@ -2602,7 +2602,8 @@ int32_t apercentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { } else { buildHistogramInfo(pInfo); if (pInfo->pHisto->numOfElems > 0) { - qDebug("get the final res:%d, elements:%"PRId64", entry:%d", pInfo->pHisto->numOfElems, pInfo->pHisto->numOfEntries); + qDebug("get the final res:%d, elements:%" PRId64 ", entry:%d", pInfo->pHisto->numOfElems, + pInfo->pHisto->numOfEntries); double ratio[] = {pInfo->percent}; double* res = tHistogramUniform(pInfo->pHisto, ratio, 1); @@ -4665,10 +4666,8 @@ int32_t csumFunction(SqlFunctionCtx* pCtx) { SSumRes* pSumRes = GET_ROWCELL_INTERBUF(pResInfo); SInputColumnInfoData* pInput = &pCtx->input; - TSKEY* tsList = (int64_t*)pInput->pPTS->pData; SColumnInfoData* pInputCol = pInput->pData[0]; - SColumnInfoData* pTsOutput = pCtx->pTsOutput; SColumnInfoData* pOutput = (SColumnInfoData*)pCtx->pOutput; int32_t numOfElems = 0; @@ -4704,11 +4703,6 @@ int32_t csumFunction(SqlFunctionCtx* pCtx) { } } - // TODO: remove this after pTsOutput is handled - if (pTsOutput != NULL) { - colDataAppendInt64(pTsOutput, pos, &tsList[i]); - } - numOfElems++; } @@ -5205,8 +5199,8 @@ bool twaFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo) { STwaInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); pInfo->isNull = false; - pInfo->p.key = INT64_MIN; - pInfo->win = TSWINDOW_INITIALIZER; + pInfo->p.key = INT64_MIN; + pInfo->win = TSWINDOW_INITIALIZER; return true; } diff --git a/source/libs/planner/test/planPartByTest.cpp b/source/libs/planner/test/planPartByTest.cpp index f1dd9403dd..256960a15e 100644 --- a/source/libs/planner/test/planPartByTest.cpp +++ b/source/libs/planner/test/planPartByTest.cpp @@ -58,7 +58,19 @@ TEST_F(PlanPartitionByTest, withInterval) { TEST_F(PlanPartitionByTest, withGroupBy) { useDb("root", "test"); - run("select count(*) from t1 partition by c1 group by c2"); + run("SELECT COUNT(*) FROM t1 PARTITION BY c1 GROUP BY c2"); run("SELECT TBNAME, c1 FROM st1 PARTITION BY TBNAME GROUP BY c1"); } + +TEST_F(PlanPartitionByTest, withTimeLineFunc) { + useDb("root", "test"); + + run("SELECT TWA(c1) FROM st1 PARTITION BY c1"); +} + +TEST_F(PlanPartitionByTest, withSlimit) { + useDb("root", "test"); + + run("SELECT CSUM(c1) FROM st1 PARTITION BY TBNAME SLIMIT 1"); +} diff --git a/tests/system-test/2-query/csum.py b/tests/system-test/2-query/csum.py index 91869cb012..bdb8c095e6 100644 --- a/tests/system-test/2-query/csum.py +++ b/tests/system-test/2-query/csum.py @@ -28,7 +28,7 @@ from util.dnodes import * class TDTestCase: def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor()) + tdSql.init(conn.cursor(), logSql) def csum_query_form(self, col="c1", alias="", table_expr="t1", condition=""): -- GitLab