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

48 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) {
2024-07-27 10:33:08 +00:00
int32_t code = 0;
2022-05-05 11:03:05 +00:00
SUdfColumnData *resultData = &resultCol->colData;
2023-03-09 12:29:42 +00:00
for (int32_t i = 0; i < block->numOfRows; ++i) {
int j = 0;
for (; j < block->numOfCols; ++j) {
if (udfColDataIsNull(block->udfCols[j], i)) {
2024-07-27 10:33:08 +00:00
code = udfColDataSetNull(resultCol, i);
if (code != 0) {
return code;
}
break;
}
}
2022-10-13 06:15:42 +00:00
if (j == block->numOfCols) {
int32_t luckyNum = 1;
2024-07-27 10:33:08 +00:00
code = udfColDataSet(resultCol, i, (char *)&luckyNum, false);
if (code != 0) {
return code;
}
}
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
2023-03-09 13:20:01 +00:00
resultData->numOfRows = block->numOfRows;
2022-04-14 11:29:41 +00:00
return 0;
2023-03-09 13:20:01 +00:00
}