Merge pull request #17448 from taosdata/fix/TD-19619
fix(query): mode function output behavior if there're multiple highest frequency of occurrence.
This commit is contained in:
commit
5cd1c12c4b
|
@ -945,7 +945,7 @@ MIN(expr)
|
|||
MODE(expr)
|
||||
```
|
||||
|
||||
**Description**:The value which has the highest frequency of occurrence. NULL is returned if there are multiple values which have highest frequency of occurrence.
|
||||
**Description**:The value which has the highest frequency of occurrence. One random value is returned if there are multiple values which have highest frequency of occurrence.
|
||||
|
||||
**Return value type**: Same as the input data
|
||||
|
||||
|
|
|
@ -946,7 +946,7 @@ MIN(expr)
|
|||
MODE(expr)
|
||||
```
|
||||
|
||||
**功能说明**:返回出现频率最高的值,若存在多个频率相同的最高值,输出NULL。
|
||||
**功能说明**:返回出现频率最高的值,若存在多个频率相同的最高值,则随机输出其中某个值。
|
||||
|
||||
**返回数据类型**:与输入数据类型一致。
|
||||
|
||||
|
|
|
@ -5359,16 +5359,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, (maxCount == 0) ? true : false);
|
||||
|
||||
return pResInfo->numOfRes;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue