From cc91ab0724cd7ad3a34dd691916d6c7a34a505ae Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Tue, 9 Nov 2021 04:37:13 -0500 Subject: [PATCH] * Solve the problem of FILL error reporting with subquery statements. * Solve the problen of disorder data returned by GROUP BY ORDER BY statement --- src/client/src/tscSQLParser.c | 2 +- src/query/src/qExecutor.c | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 777990db66..71bc9422ce 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -5417,7 +5417,7 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq if (taosArrayGetSize(pQueryInfo->pUpstream) > 0 && condExpr.pTimewindow != NULL) { setNormalExprToCond(&condExpr.pColumnCond, condExpr.pTimewindow, TK_AND); - condExpr.pTimewindow = NULL; + condExpr.pTimewindow = tSqlExprClone(condExpr.pTimewindow); } tSqlExprCompact(pExpr); diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 0cf2fbf276..de820d2201 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -277,7 +277,7 @@ static int compareRowData(const void *a, const void *b, const void *userData) { return (in1 != NULL && in2 != NULL) ? supporter->comFunc(in1, in2) : 0; } -static void sortGroupResByOrderList(SGroupResInfo *pGroupResInfo, SQueryRuntimeEnv *pRuntimeEnv, SSDataBlock* pDataBlock) { +static void sortGroupResByOrderList(SGroupResInfo *pGroupResInfo, SQueryRuntimeEnv *pRuntimeEnv, SSDataBlock* pDataBlock, SQLFunctionCtx *pCtx) { SArray *columnOrderList = getOrderCheckColumns(pRuntimeEnv->pQueryAttr); size_t size = taosArrayGetSize(columnOrderList); taosArrayDestroy(columnOrderList); @@ -291,12 +291,23 @@ static void sortGroupResByOrderList(SGroupResInfo *pGroupResInfo, SQueryRuntimeE return; } + int32_t orderIndex = -1; + for (int32_t j = 0; j < pDataBlock->info.numOfCols; ++j) { + if (pCtx[j].colId == orderId) { + orderIndex = j; + break; + } + } + if (orderIndex < 0) { + return; + } + bool found = false; int16_t dataOffset = 0; for (int32_t j = 0; j < pDataBlock->info.numOfCols; ++j) { SColumnInfoData* pColInfoData = (SColumnInfoData *)taosArrayGet(pDataBlock->pDataBlock, j); - if (orderId == j) { + if (orderIndex == j) { found = true; break; } @@ -308,8 +319,7 @@ static void sortGroupResByOrderList(SGroupResInfo *pGroupResInfo, SQueryRuntimeE return; } - int16_t type = pRuntimeEnv->pQueryAttr->pExpr1[orderId].base.resType; - + int16_t type = pRuntimeEnv->pQueryAttr->pExpr1[orderIndex].base.resType; SRowCompSupporter support = {.pRuntimeEnv = pRuntimeEnv, .dataOffset = dataOffset, .comFunc = getComparFunc(type, 0)}; taosArraySortPWithExt(pGroupResInfo->pRows, compareRowData, &support); } @@ -6472,7 +6482,7 @@ static SSDataBlock* hashGroupbyAggregate(void* param, bool* newgroup) { initGroupResInfo(&pRuntimeEnv->groupResInfo, &pInfo->binfo.resultRowInfo); if (!pRuntimeEnv->pQueryAttr->stableQuery) { - sortGroupResByOrderList(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pInfo->binfo.pRes); + sortGroupResByOrderList(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pInfo->binfo.pRes, pInfo->binfo.pCtx); } toSSDataBlock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pInfo->binfo.pRes); -- GitLab