From 0408e5fa6167f4cc63c9b9c85adffa6c38f828c5 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Thu, 10 Mar 2022 18:13:57 +0800 Subject: [PATCH] [TS-207](query): sortGroupResByOrder function fixed groupby colid --- src/query/src/qExecutor.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 3af08a2eef..f125e968cb 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -289,43 +289,35 @@ static int compareRowData(const void *a, const void *b, const void *userData) { } static void sortGroupResByOrderList(SGroupResInfo *pGroupResInfo, SQueryRuntimeEnv *pRuntimeEnv, SSDataBlock* pDataBlock, SQLFunctionCtx *pCtx) { - SArray *columnOrderList = getOrderCheckColumns(pRuntimeEnv->pQueryAttr); - size_t size = taosArrayGetSize(columnOrderList); - taosArrayDestroy(&columnOrderList); - - if (size <= 0) { - return; - } - - int32_t orderId = pRuntimeEnv->pQueryAttr->order.orderColId; - if (orderId <= 0) { + // get groupby first column index + SColIndex* pColIndex = taosArrayGet(pRuntimeEnv->pQueryAttr->pGroupbyExpr->columnInfo, 0); + if (pColIndex == NULL) { return; } + // search group by col index int32_t orderIndex = -1; for (int32_t j = 0; j < pDataBlock->info.numOfCols; ++j) { - if (pCtx[j].colId == orderId) { + if (pCtx[j].colId == pColIndex->colId) { orderIndex = j; break; } } - if (orderIndex < 0) { + if (orderIndex == -1) { return; } + // get dataOffset 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 (orderIndex == j) { found = true; break; } - dataOffset += pColInfoData->info.bytes; } - if (found == false) { return; } -- GitLab