提交 33f3b5fa 编写于 作者: A Alex Duan

[TS-207]<fix>(query): simple sortGroupbyColumn flow

上级 7de84b9d
...@@ -289,40 +289,30 @@ static int compareRowData(const void *a, const void *b, const void *userData) { ...@@ -289,40 +289,30 @@ static int compareRowData(const void *a, const void *b, const void *userData) {
} }
static void sortGroupResByOrderList(SGroupResInfo *pGroupResInfo, SQueryRuntimeEnv *pRuntimeEnv, SSDataBlock* pDataBlock, SQLFunctionCtx *pCtx) { static void sortGroupResByOrderList(SGroupResInfo *pGroupResInfo, SQueryRuntimeEnv *pRuntimeEnv, SSDataBlock* pDataBlock, SQLFunctionCtx *pCtx) {
// get groupby first column index // first groupby column is sort column
SColIndex* pColIndex = taosArrayGet(pRuntimeEnv->pQueryAttr->pGroupbyExpr->columnInfo, 0); SColIndex* pFirstGroupCol = taosArrayGet(pRuntimeEnv->pQueryAttr->pGroupbyExpr->columnInfo, 0);
if (pColIndex == NULL) { if (pFirstGroupCol == NULL) {
return; return;
} }
// search group by col index // get dataOffset and index on pRuntimeEnv->pQueryAttr->pExpr1
int32_t orderIndex = -1; int32_t idxGroup = -1;
for (int32_t j = 0; j < pDataBlock->info.numOfCols; ++j) {
if (pCtx[j].colId == pColIndex->colId) {
orderIndex = j;
break;
}
}
if (orderIndex == -1) {
return;
}
// get dataOffset
bool found = false;
int16_t dataOffset = 0; int16_t dataOffset = 0;
for (int32_t j = 0; j < pDataBlock->info.numOfCols; ++j) { for (int32_t j = 0; j < pDataBlock->info.numOfCols; ++j) {
SColumnInfoData* pColInfoData = (SColumnInfoData *)taosArrayGet(pDataBlock->pDataBlock, j); SColumnInfoData* pColInfoData = (SColumnInfoData *)taosArrayGet(pDataBlock->pDataBlock, j);
if (orderIndex == j) { if (pCtx[j].colId == pFirstGroupCol->colId) {
found = true; idxGroup = j;
break; break;
} }
dataOffset += pColInfoData->info.bytes; dataOffset += pColInfoData->info.bytes;
} }
if (found == false) { // check found
if (idxGroup == -1) {
qError("sort groupby not found first column. first colId=%d", pFirstGroupCol->colId);
return; return;
} }
int16_t type = pRuntimeEnv->pQueryAttr->pExpr1[orderIndex].base.resType; int16_t type = pRuntimeEnv->pQueryAttr->pExpr1[idxGroup].base.resType;
SRowCompSupporter support = {.pRuntimeEnv = pRuntimeEnv, .dataOffset = dataOffset, .comFunc = getComparFunc(type, 0)}; SRowCompSupporter support = {.pRuntimeEnv = pRuntimeEnv, .dataOffset = dataOffset, .comFunc = getComparFunc(type, 0)};
taosArraySortPWithExt(pGroupResInfo->pRows, compareRowData, &support); taosArraySortPWithExt(pGroupResInfo->pRows, compareRowData, &support);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册