Merge pull request #12717 from taosdata/feature/udf

fix: udf2 reuse old state when new input is all null
This commit is contained in:
shenglian-zhou 2022-05-19 21:11:38 +08:00 committed by GitHub
commit 5049ea17e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 7 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,14 @@ 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) {
if (interBuf->numOfResult == 0 && numOutput == 0) {
newInterBuf->numOfResult = 0; newInterBuf->numOfResult = 0;
} else { } else {
newInterBuf->numOfResult = 1; newInterBuf->numOfResult = 1;