fix: udf2 support int and double data type
This commit is contained in:
parent
3967f79b38
commit
73d55e7c6b
|
@ -19,17 +19,18 @@ int32_t udf2_destroy() {
|
||||||
|
|
||||||
int32_t udf2_start(SUdfInterBuf *buf) {
|
int32_t udf2_start(SUdfInterBuf *buf) {
|
||||||
*(int64_t*)(buf->buf) = 0;
|
*(int64_t*)(buf->buf) = 0;
|
||||||
buf->bufLen = sizeof(int64_t);
|
buf->bufLen = sizeof(double);
|
||||||
buf->numOfResult = 0;
|
buf->numOfResult = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t udf2(SUdfDataBlock* block, SUdfInterBuf *interBuf, SUdfInterBuf *newInterBuf) {
|
int32_t udf2(SUdfDataBlock* block, SUdfInterBuf *interBuf, SUdfInterBuf *newInterBuf) {
|
||||||
int64_t sumSquares = *(int64_t*)interBuf->buf;
|
double sumSquares = *(double*)interBuf->buf;
|
||||||
int8_t numOutput = 0;
|
int8_t numOutput = 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 ||
|
||||||
|
col->colMeta.type == TSDB_DATA_TYPE_DOUBLE)) {
|
||||||
return TSDB_CODE_UDF_INVALID_INPUT;
|
return TSDB_CODE_UDF_INVALID_INPUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,17 +40,29 @@ int32_t udf2(SUdfDataBlock* block, SUdfInterBuf *interBuf, SUdfInterBuf *newInte
|
||||||
if (udfColDataIsNull(col, j)) {
|
if (udfColDataIsNull(col, j)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
switch (col->colMeta.type) {
|
||||||
char* cell = udfColDataGetData(col, j);
|
case TSDB_DATA_TYPE_INT: {
|
||||||
int32_t num = *(int32_t*)cell;
|
char* cell = udfColDataGetData(col, j);
|
||||||
sumSquares += num * num;
|
int32_t num = *(int32_t*)cell;
|
||||||
|
sumSquares += num * num;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case TSDB_DATA_TYPE_DOUBLE: {
|
||||||
|
char* cell = udfColDataGetData(col, j);
|
||||||
|
double num = *(double*)cell;
|
||||||
|
sumSquares += num * num;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
numOutput = 1;
|
numOutput = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numOutput == 1) {
|
if (numOutput == 1) {
|
||||||
*(int64_t*)(newInterBuf->buf) = sumSquares;
|
*(double*)(newInterBuf->buf) = sumSquares;
|
||||||
newInterBuf->bufLen = sizeof(int64_t);
|
newInterBuf->bufLen = sizeof(double);
|
||||||
}
|
}
|
||||||
newInterBuf->numOfResult = numOutput;
|
newInterBuf->numOfResult = numOutput;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -60,7 +73,7 @@ int32_t udf2_finish(SUdfInterBuf* buf, SUdfInterBuf *resultData) {
|
||||||
resultData->numOfResult = 0;
|
resultData->numOfResult = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int64_t sumSquares = *(int64_t*)(buf->buf);
|
double sumSquares = *(double*)(buf->buf);
|
||||||
*(double*)(resultData->buf) = sqrt(sumSquares);
|
*(double*)(resultData->buf) = sqrt(sumSquares);
|
||||||
resultData->bufLen = sizeof(double);
|
resultData->bufLen = sizeof(double);
|
||||||
resultData->numOfResult = 1;
|
resultData->numOfResult = 1;
|
||||||
|
|
Loading…
Reference in New Issue