diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index bc003a3024d53df0acfa05a642236afad1ac5a33..d3d05acd3c5d7302283d1f9280386f8068915262 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -3530,7 +3530,12 @@ int32_t csumFunction(SqlFunctionCtx* pCtx) { double v; GET_TYPED_DATA(v, double, type, data); pSumRes->dsum += v; - colDataAppend(pOutput, pos, (char *)&pSumRes->dsum, false); + //check for overflow + if (isinf(pSumRes->dsum) || isnan(pSumRes->dsum)) { + colDataAppendNULL(pOutput, pos); + } else { + colDataAppend(pOutput, pos, (char *)&pSumRes->dsum, false); + } } //TODO: remove this after pTsOutput is handled @@ -3604,7 +3609,12 @@ int32_t mavgFunction(SqlFunctionCtx* pCtx) { pInfo->points[pInfo->pos] = v; double result = pInfo->sum / pInfo->numOfPoints; - colDataAppend(pOutput, pos, (char *)&result, false); + //check for overflow + if (isinf(result) || isnan(result)) { + colDataAppendNULL(pOutput, pos); + } else { + colDataAppend(pOutput, pos, (char *)&result, false); + } //TODO: remove this after pTsOutput is handled if (pTsOutput != NULL) {