TDengine/source/libs/function/test/udf1.c

40 lines
873 B
C
Raw Normal View History

2022-03-24 08:59:43 +00:00
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "taosudf.h"
2022-04-14 11:29:41 +00:00
2022-04-15 04:19:22 +00:00
2022-06-05 09:02:43 +00:00
DLL_EXPORT int32_t udf1_init() {
2022-04-14 11:29:41 +00:00
return 0;
}
2022-06-05 09:02:43 +00:00
DLL_EXPORT int32_t udf1_destroy() {
2022-04-14 11:29:41 +00:00
return 0;
2022-03-24 08:59:43 +00:00
}
2022-04-14 11:29:41 +00:00
2022-06-05 09:02:43 +00:00
DLL_EXPORT int32_t udf1(SUdfDataBlock* block, SUdfColumn *resultCol) {
2022-04-19 08:51:02 +00:00
SUdfColumnMeta *meta = &resultCol->colMeta;
meta->bytes = 4;
meta->type = TSDB_DATA_TYPE_INT;
meta->scale = 0;
meta->precision = 0;
2022-04-14 11:29:41 +00:00
2022-05-05 11:03:05 +00:00
SUdfColumnData *resultData = &resultCol->colData;
resultData->numOfRows = block->numOfRows;
for (int32_t i = 0; i < resultData->numOfRows; ++i) {
int j = 0;
for (; j < block->numOfCols; ++j) {
if (udfColDataIsNull(block->udfCols[j], i)) {
udfColDataSetNull(resultCol, i);
break;
}
}
if ( j == block->numOfCols) {
int32_t luckyNum = 88;
udfColDataSet(resultCol, i, (char *)&luckyNum, false);
}
2022-04-14 11:29:41 +00:00
}
2022-05-05 11:03:05 +00:00
2022-04-14 11:29:41 +00:00
return 0;
}