diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index da842877dcdb9afcb2d32dbf47dada1864a35972..659c7447d608f22ca42e26b65df4e02fb33be585 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); }