提交 b8ce9100 编写于 作者: A Alex Duan

[TS-207]<fix>(query): sortGroupResByOrder function fixed groupby colid

上级 27273faa
...@@ -283,28 +283,41 @@ static int compareRowData(const void *a, const void *b, const void *userData) { ...@@ -283,28 +283,41 @@ static int compareRowData(const void *a, const void *b, const void *userData) {
return (in1 != NULL && in2 != NULL) ? supporter->comFunc(in1, in2) : 0; 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) {
if (pRuntimeEnv->pQueryAttr->pGroupbyExpr == NULL || pRuntimeEnv->pQueryAttr->pGroupbyExpr->numOfGroupCols <= 0){ // get groupby first column index
SColIndex* pColIndex = taosArrayGet(pRuntimeEnv->pQueryAttr->pGroupbyExpr->columnInfo, 0);
if (pColIndex == NULL) {
return; return;
} }
if (pRuntimeEnv->pQueryAttr->order.orderColId <= 0){ // search group by col index
int32_t orderIndex = -1;
for (int32_t j = 0; j < pDataBlock->info.numOfCols; ++j) {
if (pCtx[j].colId == pColIndex->colId) {
orderIndex = j;
break;
}
}
if (orderIndex == -1) {
return; return;
} }
SColIndex* pColIndex = taosArrayGet(pRuntimeEnv->pQueryAttr->pGroupbyExpr->columnInfo, 0); // get dataOffset
bool found = false;
int16_t dataOffset = 0; int16_t dataOffset = 0;
int16_t type = 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 (pColInfoData->info.colId == pColIndex->colId) { if (orderIndex == j) {
type = pColInfoData->info.type; found = true;
break; break;
} }
dataOffset += pColInfoData->info.bytes; dataOffset += pColInfoData->info.bytes;
} }
if (found == false) {
return;
}
int16_t type = pRuntimeEnv->pQueryAttr->pExpr1[orderIndex].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);
} }
...@@ -7127,7 +7140,7 @@ static SSDataBlock* hashGroupbyAggregate(void* param, bool* newgroup) { ...@@ -7127,7 +7140,7 @@ static SSDataBlock* hashGroupbyAggregate(void* param, bool* newgroup) {
initGroupResInfo(&pRuntimeEnv->groupResInfo, &pInfo->binfo.resultRowInfo); initGroupResInfo(&pRuntimeEnv->groupResInfo, &pInfo->binfo.resultRowInfo);
if (!pRuntimeEnv->pQueryAttr->stableQuery) { 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); toSSDataBlock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pInfo->binfo.pRes);
...@@ -9553,7 +9566,6 @@ SQInfo* createQInfoImpl(SQueryTableMsg* pQueryMsg, SGroupbyExpr* pGroupbyExpr, S ...@@ -9553,7 +9566,6 @@ SQInfo* createQInfoImpl(SQueryTableMsg* pQueryMsg, SGroupbyExpr* pGroupbyExpr, S
pQueryAttr->needTableSeqScan = pQueryMsg->needTableSeqScan; pQueryAttr->needTableSeqScan = pQueryMsg->needTableSeqScan;
pQueryAttr->needReverseScan = pQueryMsg->needReverseScan; pQueryAttr->needReverseScan = pQueryMsg->needReverseScan;
pQueryAttr->stateWindow = pQueryMsg->stateWindow; pQueryAttr->stateWindow = pQueryMsg->stateWindow;
pQueryAttr->vgId = vgId;
pQueryAttr->pFilters = pFilters; pQueryAttr->pFilters = pFilters;
pQueryAttr->range = pQueryMsg->range; pQueryAttr->range = pQueryMsg->range;
......
...@@ -183,16 +183,16 @@ int32_t compareLenPrefixedStr(const void *pLeft, const void *pRight) { ...@@ -183,16 +183,16 @@ int32_t compareLenPrefixedStr(const void *pLeft, const void *pRight) {
int32_t len1 = varDataLen(pLeft); int32_t len1 = varDataLen(pLeft);
int32_t len2 = varDataLen(pRight); int32_t len2 = varDataLen(pRight);
if (len1 != len2) { int32_t ret = strncmp(varDataVal(pLeft), varDataVal(pRight), len1>len2 ? len2:len1);
return len1 > len2? 1:-1; if (ret == 0) {
} else { if (len1 > len2)
int32_t ret = strncmp(varDataVal(pLeft), varDataVal(pRight), len1); return 1;
if (ret == 0) { else if(len1 < len2)
return -1;
else
return 0; return 0;
} else {
return ret > 0 ? 1:-1;
}
} }
return (ret < 0) ? -1 : 1;
} }
int32_t compareLenPrefixedStrDesc(const void* pLeft, const void* pRight) { int32_t compareLenPrefixedStrDesc(const void* pLeft, const void* pRight) {
...@@ -203,16 +203,16 @@ int32_t compareLenPrefixedWStr(const void *pLeft, const void *pRight) { ...@@ -203,16 +203,16 @@ int32_t compareLenPrefixedWStr(const void *pLeft, const void *pRight) {
int32_t len1 = varDataLen(pLeft); int32_t len1 = varDataLen(pLeft);
int32_t len2 = varDataLen(pRight); int32_t len2 = varDataLen(pRight);
if (len1 != len2) { int32_t ret = tasoUcs4Compare(varDataVal(pLeft), varDataVal(pRight), len1>len2 ? len2:len1);
return len1 > len2? 1:-1; if (ret == 0) {
} else { if (len1 > len2)
int32_t ret = memcmp((wchar_t*) pLeft, (wchar_t*) pRight, len1); return 1;
if (ret == 0) { else if(len1 < len2)
return -1;
else
return 0; return 0;
} else {
return ret > 0 ? 1 : -1;
}
} }
return (ret < 0) ? -1 : 1;
} }
int32_t compareLenPrefixedWStrDesc(const void* pLeft, const void* pRight) { int32_t compareLenPrefixedWStrDesc(const void* pLeft, const void* pRight) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册