From dc17e5553c962dacdd0d69ad2f18fabc068cd73b Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Fri, 27 May 2022 15:29:33 +0800 Subject: [PATCH] fix(query): eliminate diff function result nan/inf in case of overflow TD-16053 --- source/libs/function/src/builtinsimpl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index d3d05acd3c..e3db81f8ef 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -2349,7 +2349,7 @@ static void doHandleDiff(SDiffInfo* pDiffInfo, int32_t type, const char* pv, SCo case TSDB_DATA_TYPE_FLOAT: { float v = *(float*)pv; float delta = factor*(v - pDiffInfo->prev.d64); // direct previous may be null - if (delta < 0 && pDiffInfo->ignoreNegative) { + if ((delta < 0 && pDiffInfo->ignoreNegative) || isinf(delta) || isnan(delta)) { //check for overflow colDataSetNull_f(pOutput->nullbitmap, pos); } else { colDataAppendFloat(pOutput, pos, &delta); @@ -2360,7 +2360,7 @@ static void doHandleDiff(SDiffInfo* pDiffInfo, int32_t type, const char* pv, SCo case TSDB_DATA_TYPE_DOUBLE: { double v = *(double*)pv; double delta = factor*(v - pDiffInfo->prev.d64); // direct previous may be null - if (delta < 0 && pDiffInfo->ignoreNegative) { + if ((delta < 0 && pDiffInfo->ignoreNegative) || isinf(delta) || isnan(delta)) { //check for overflow colDataSetNull_f(pOutput->nullbitmap, pos); } else { colDataAppendDouble(pOutput, pos, &delta); -- GitLab