From 72d9b078946377053d7c45ec254a3b1756438193 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Thu, 26 May 2022 11:36:07 +0800 Subject: [PATCH] fix(query): fix avg/sum function result overflown output inf/nan TD-15923 --- source/libs/function/src/builtinsimpl.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index da842877dc..659c7447d6 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -502,6 +502,11 @@ int32_t sumFunction(SqlFunctionCtx* pCtx) { } } + //check for overflow + if (isinf(pSumRes->dsum) || isnan(pSumRes->dsum)) { + GET_RES_INFO(pCtx)->isNullRes = 1; + } + _sum_over: // data in the check operation are all null, not output SET_VAL(GET_RES_INFO(pCtx), numOfElem, 1); @@ -813,6 +818,9 @@ 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); } -- GitLab