From 2884b36d5fe31f46aace849f9dded53991a8a120 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Tue, 26 Jul 2022 20:07:28 +0800 Subject: [PATCH 1/5] fix(query): fix sum(null) or sum(nullexpr) result to null --- source/libs/function/src/builtinsimpl.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 5ad433c9ff..18bc74e57d 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -466,7 +466,7 @@ int32_t functionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId); SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); - pResInfo->isNullRes = (pResInfo->numOfRes == 0) ? 1 : 0; + pResInfo->isNullRes = (pResInfo->isNullRes == 1) ? 1 : (pResInfo->numOfRes == 0) ? 1 : 0; char* in = GET_ROWCELL_INTERBUF(pResInfo); colDataAppend(pCol, pBlock->info.rows, in, pResInfo->isNullRes); @@ -662,8 +662,9 @@ int32_t sumFunction(SqlFunctionCtx* pCtx) { } // check for overflow - if (IS_FLOAT_TYPE(type) && (isinf(pSumRes->dsum) || isnan(pSumRes->dsum))) { - numOfElem = 0; + if (numOfElem == 0 || (IS_FLOAT_TYPE(type) && (isinf(pSumRes->dsum) || isnan(pSumRes->dsum)))) { + GET_RES_INFO(pCtx)->isNullRes = 1; + numOfElem = 1; } _sum_over: From 2dc24b26922d355c5ae54e16e7566c6b4c53ccaa Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Tue, 26 Jul 2022 20:07:28 +0800 Subject: [PATCH 2/5] fix(query): fix max/min with null input --- 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 18bc74e57d..790f5d03a3 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -466,7 +466,7 @@ int32_t functionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId); SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); - pResInfo->isNullRes = (pResInfo->isNullRes == 1) ? 1 : (pResInfo->numOfRes == 0) ? 1 : 0; + pResInfo->isNullRes = (pResInfo->isNullRes == 1) ? 1 : (pResInfo->numOfRes == 0); char* in = GET_ROWCELL_INTERBUF(pResInfo); colDataAppend(pCol, pBlock->info.rows, in, pResInfo->isNullRes); @@ -1606,7 +1606,7 @@ int32_t minmaxFunctionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { int32_t currentRow = pBlock->info.rows; SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId); - pEntryInfo->isNullRes = (pEntryInfo->numOfRes == 0); + pEntryInfo->isNullRes = (pEntryInfo->isNullRes == 1) ? 1 : (pEntryInfo->numOfRes == 0); if (pCol->info.type == TSDB_DATA_TYPE_FLOAT) { float v = *(double*)&pRes->v; From 320525edf988c75b816da3c43de6370c8fec5c94 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Tue, 26 Jul 2022 20:07:28 +0800 Subject: [PATCH 3/5] fix(query): fix max/min with null input --- source/libs/function/src/builtinsimpl.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 790f5d03a3..bc24f54b52 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -1577,6 +1577,11 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { } } + if (numOfElems == 0) { + GET_RES_INFO(pCtx)->isNullRes = 1; + numOfElems = 1; + } + _min_max_over: return numOfElems; } From c0091afb018eb2cc9b67471afbb3ebf2b16ecc8c Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Tue, 26 Jul 2022 20:23:13 +0800 Subject: [PATCH 4/5] Merge branch '3.0' into enh/TD-17659 --- source/libs/function/src/builtinsimpl.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 06011b2641..fb82ab206c 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -662,7 +662,7 @@ int32_t sumFunction(SqlFunctionCtx* pCtx) { } // check for overflow - if (numOfElem == 0 || (IS_FLOAT_TYPE(type) && (isinf(pSumRes->dsum) || isnan(pSumRes->dsum)))) { + if (IS_FLOAT_TYPE(type) && (isinf(pSumRes->dsum) || isnan(pSumRes->dsum))) { GET_RES_INFO(pCtx)->isNullRes = 1; numOfElem = 1; } @@ -1577,11 +1577,6 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { } } - if (numOfElems == 0) { - GET_RES_INFO(pCtx)->isNullRes = 1; - numOfElems = 1; - } - _min_max_over: return numOfElems; } From c087a8d55197cd05f2b115a30f4f61574a0f871c Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 27 Jul 2022 11:19:29 +0800 Subject: [PATCH 5/5] fix test case --- tests/script/tsim/stream/session0.sim | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/script/tsim/stream/session0.sim b/tests/script/tsim/stream/session0.sim index 16a53d49f3..d05a9e1814 100644 --- a/tests/script/tsim/stream/session0.sim +++ b/tests/script/tsim/stream/session0.sim @@ -83,22 +83,22 @@ if $data11 != 3 then goto loop0 endi -if $data12 != 10 then +if $data12 != NULL then print ======data12=$data12 goto loop0 endi -if $data13 != 10 then +if $data13 != NULL then print ======data13=$data13 goto loop0 endi -if $data14 != 1.100000000 then +if $data14 != NULL then print ======data14=$data14 return -1 endi -if $data15 != 0.000000000 then +if $data15 != NULL then print ======data15=$data15 return -1 endi @@ -141,22 +141,22 @@ if $data01 != 7 then goto loop1 endi -if $data02 != 18 then +if $data02 != NULL then print =====data02=$data02 goto loop1 endi -if $data03 != 4 then +if $data03 != NULL then print =====data03=$data03 goto loop1 endi -if $data04 != 1.000000000 then +if $data04 != NULL then print ======$data04 return -1 endi -if $data05 != 1.154700538 then +if $data05 != NULL then print ======$data05 return -1 endi