From d11303916b63d624081951e9a3188f5b9e19c2ef Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Fri, 27 May 2022 22:59:17 +0800 Subject: [PATCH] fix(query): fix avg used in group by NULL value calculated as nan TD-15892 --- source/libs/function/src/builtinsimpl.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 154ba43d51..3ffb8a97d8 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -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); } -- GitLab