From c0fc53a9a886e75aec314d54b89311d417ef5400 Mon Sep 17 00:00:00 2001 From: slzhou Date: Thu, 19 May 2022 20:54:30 +0800 Subject: [PATCH] fix: udf2 reuse old state when new input is null --- source/libs/function/test/udf2.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/source/libs/function/test/udf2.c b/source/libs/function/test/udf2.c index 6410af2a4b..49d681f5eb 100644 --- a/source/libs/function/test/udf2.c +++ b/source/libs/function/test/udf2.c @@ -26,7 +26,7 @@ int32_t udf2_start(SUdfInterBuf *buf) { int32_t udf2(SUdfDataBlock* block, SUdfInterBuf *interBuf, SUdfInterBuf *newInterBuf) { double sumSquares = *(double*)interBuf->buf; - int8_t numOutput = 0; + int8_t numNotNull = 0; for (int32_t i = 0; i < block->numOfCols; ++i) { SUdfColumn* col = block->udfCols[i]; if (!(col->colMeta.type == TSDB_DATA_TYPE_INT || @@ -56,15 +56,18 @@ int32_t udf2(SUdfDataBlock* block, SUdfInterBuf *interBuf, SUdfInterBuf *newInte default: break; } - numOutput = 1; + ++numNotNull; } } - if (numOutput == 1) { - *(double*)(newInterBuf->buf) = sumSquares; - newInterBuf->bufLen = sizeof(double); + *(double*)(newInterBuf->buf) = sumSquares; + newInterBuf->bufLen = sizeof(double); + + if (interBuf->numOfResult == 0 && numNotNull == 0) { + newInterBuf->numOfResult = 0; + } else { + newInterBuf->numOfResult = 1; } - newInterBuf->numOfResult = numOutput; return 0; }