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

46 lines
1.1 KiB
C
Raw Normal View History

2022-03-24 08:59:43 +00:00
#include <stdio.h>
2022-10-13 06:15:42 +00:00
#include <stdlib.h>
#include <string.h>
2022-07-25 10:37:29 +00:00
#ifdef LINUX
#include <unistd.h>
2022-07-25 10:37:29 +00:00
#endif
#ifdef WINDOWS
#include <windows.h>
#endif
#include "taosudf.h"
2022-04-14 11:29:41 +00:00
2022-10-13 06:15:42 +00:00
DLL_EXPORT int32_t udf1_init() { return 0; }
2022-04-15 04:19:22 +00:00
2022-10-13 06:15:42 +00:00
DLL_EXPORT int32_t udf1_destroy() { return 0; }
2022-04-14 11:29:41 +00:00
2022-10-13 06:15:42 +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;
}
}
2022-10-13 06:15:42 +00:00
if (j == block->numOfCols) {
int32_t luckyNum = 88;
udfColDataSet(resultCol, i, (char *)&luckyNum, false);
}
2022-04-14 11:29:41 +00:00
}
2022-10-13 06:15:42 +00:00
// to simulate actual processing delay by udf
2022-07-25 10:37:29 +00:00
#ifdef LINUX
2022-10-13 06:15:42 +00:00
usleep(1 * 1000); // usleep takes sleep time in us (1 millionth of a second)
2022-07-25 10:37:29 +00:00
#endif
#ifdef WINDOWS
2022-07-25 10:37:29 +00:00
Sleep(1);
#endif
2022-04-14 11:29:41 +00:00
return 0;
}