From de6f6a1e3588cf4a347be1dc1e5b4c483334681e Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Fri, 27 May 2022 15:29:33 +0800 Subject: [PATCH] fix(query): eliminate csum/mavg result nan/inf in case of overflow TD-16053 --- source/libs/function/src/builtinsimpl.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index bc003a3024..d3d05acd3c 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) { -- GitLab