Merge pull request #13113 from taosdata/fix/TD-15892

fix(query): fix avg used in group by NULL value calculated as nan
This commit is contained in:
Ganlin Zhao 2022-05-27 23:32:37 +08:00 committed by GitHub
commit 06a5408190
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -834,12 +834,14 @@ int32_t avgFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
if (IS_INTEGER_TYPE(type)) {
pAvgRes->result = pAvgRes->sum.isum / ((double)pAvgRes->count);
} else {
if (isinf(pAvgRes->sum.dsum) || isnan(pAvgRes->sum.dsum)) {
GET_RES_INFO(pCtx)->isNullRes = 1;
}
pAvgRes->result = pAvgRes->sum.dsum / ((double)pAvgRes->count);
}
//check for overflow
if (isinf(pAvgRes->result) || isnan(pAvgRes->result)) {
GET_RES_INFO(pCtx)->isNullRes = 1;
}
return functionFinalize(pCtx, pBlock);
}