fix(query): mode function output one random result instead of NULL

if there're multiple highest frequency of occurrence.

TD-19619
This commit is contained in:
Ganlin Zhao 2022-10-18 17:52:40 +08:00
parent 194587558b
commit 0f5e02b0b4
1 changed files with 2 additions and 4 deletions

View File

@ -5356,16 +5356,14 @@ int32_t modeFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
int32_t maxCount = 0;
for (int32_t i = 0; i < pInfo->numOfPoints; ++i) {
SModeItem* pItem = (SModeItem*)(pInfo->pItems + i * (sizeof(SModeItem) + pInfo->colBytes));
if (pItem->count > maxCount) {
if (pItem->count >= maxCount) {
maxCount = pItem->count;
resIndex = i;
} else if (pItem->count == maxCount) {
resIndex = -1;
}
}
SModeItem* pResItem = (SModeItem*)(pInfo->pItems + resIndex * (sizeof(SModeItem) + pInfo->colBytes));
colDataAppend(pCol, currentRow, pResItem->data, (resIndex == -1) ? true : false);
colDataAppend(pCol, currentRow, pResItem->data, false);
return pResInfo->numOfRes;
}