fix: udf2 reuse old state when new input is null

This commit is contained in:
slzhou 2022-05-19 20:54:30 +08:00
parent 36dcc70f0d
commit c0fc53a9a8
1 changed files with 9 additions and 6 deletions

View File

@ -26,7 +26,7 @@ int32_t udf2_start(SUdfInterBuf *buf) {
int32_t udf2(SUdfDataBlock* block, SUdfInterBuf *interBuf, SUdfInterBuf *newInterBuf) { int32_t udf2(SUdfDataBlock* block, SUdfInterBuf *interBuf, SUdfInterBuf *newInterBuf) {
double sumSquares = *(double*)interBuf->buf; double sumSquares = *(double*)interBuf->buf;
int8_t numOutput = 0; int8_t numNotNull = 0;
for (int32_t i = 0; i < block->numOfCols; ++i) { for (int32_t i = 0; i < block->numOfCols; ++i) {
SUdfColumn* col = block->udfCols[i]; SUdfColumn* col = block->udfCols[i];
if (!(col->colMeta.type == TSDB_DATA_TYPE_INT || if (!(col->colMeta.type == TSDB_DATA_TYPE_INT ||
@ -56,15 +56,18 @@ int32_t udf2(SUdfDataBlock* block, SUdfInterBuf *interBuf, SUdfInterBuf *newInte
default: default:
break; break;
} }
numOutput = 1; ++numNotNull;
} }
} }
if (numOutput == 1) { *(double*)(newInterBuf->buf) = sumSquares;
*(double*)(newInterBuf->buf) = sumSquares; newInterBuf->bufLen = sizeof(double);
newInterBuf->bufLen = sizeof(double);
if (interBuf->numOfResult == 0 && numNotNull == 0) {
newInterBuf->numOfResult = 0;
} else {
newInterBuf->numOfResult = 1;
} }
newInterBuf->numOfResult = numOutput;
return 0; return 0;
} }