From 1e8dcacea6347367315d5d2bacd96828bb793815 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sun, 27 Nov 2022 18:25:20 +0800 Subject: [PATCH] fix(query): set null for inf and nan value. --- source/libs/function/src/detail/tavgfunction.c | 7 ++++++- tests/system-test/2-query/avg.py | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/source/libs/function/src/detail/tavgfunction.c b/source/libs/function/src/detail/tavgfunction.c index 267cb36769..7d018a8dc7 100644 --- a/source/libs/function/src/detail/tavgfunction.c +++ b/source/libs/function/src/detail/tavgfunction.c @@ -723,7 +723,12 @@ int32_t avgFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { } } - pEntryInfo->numOfRes = (pRes->count > 0)? 1:0; + if (pRes->count == 0 || isinf(pRes->result) || isnan(pRes->result)) { + pEntryInfo->numOfRes = 0; + } else { + pEntryInfo->numOfRes = 1; + } + return functionFinalize(pCtx, pBlock); } diff --git a/tests/system-test/2-query/avg.py b/tests/system-test/2-query/avg.py index 139e7d4bf4..1d4d9a2494 100644 --- a/tests/system-test/2-query/avg.py +++ b/tests/system-test/2-query/avg.py @@ -15,7 +15,7 @@ class TDTestCase: def init(self, conn, logSql, replicaVar=1): self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") - tdSql.init(conn.cursor(), False) + tdSql.init(conn.cursor(), True) self.setsql = TDSetSql() self.column_dict = { 'ts':'timestamp', @@ -413,7 +413,7 @@ class TDTestCase: tdSql.checkData(0,2,14042.142857143) tdSql.checkData(0,3,53.571428571) tdSql.checkData(0,4,5.828571332045761e+37) - tdSql.checkData(0,5,math.inf) + tdSql.checkData(0,5,None) # check + - * / in functions @@ -423,7 +423,7 @@ class TDTestCase: tdSql.checkData(0,2,14042.142857143) tdSql.checkData(0,3,26.785714286) tdSql.checkData(0,4,2.9142856660228804e+37) - tdSql.checkData(0,5,math.inf) + tdSql.checkData(0,5,None)