udf1.c 1.1 KB
Newer Older
S
shenglian zhou 已提交
1 2 3
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
S
shenglian zhou 已提交
4
#ifdef LINUX
5
#include <unistd.h>
S
shenglian zhou 已提交
6 7 8 9
#endif
#ifdef WINDOWS
#include <windows.h>
#endif
10
#include "taosudf.h"
S
shenglian zhou 已提交
11

S
slzhou 已提交
12

wafwerar's avatar
wafwerar 已提交
13
DLL_EXPORT int32_t udf1_init() {
S
shenglian zhou 已提交
14 15 16
  return 0;
}

wafwerar's avatar
wafwerar 已提交
17
DLL_EXPORT int32_t udf1_destroy() {
S
shenglian zhou 已提交
18
  return 0;
S
shenglian zhou 已提交
19
}
S
shenglian zhou 已提交
20

wafwerar's avatar
wafwerar 已提交
21
DLL_EXPORT int32_t udf1(SUdfDataBlock* block, SUdfColumn *resultCol) {
S
slzhou 已提交
22 23 24 25 26
  SUdfColumnMeta *meta = &resultCol->colMeta;
  meta->bytes = 4;
  meta->type = TSDB_DATA_TYPE_INT;
  meta->scale = 0;
  meta->precision = 0;
S
shenglian zhou 已提交
27

S
shenglian zhou 已提交
28 29 30
  SUdfColumnData *resultData = &resultCol->colData;
  resultData->numOfRows = block->numOfRows;
  for (int32_t i = 0; i < resultData->numOfRows; ++i) {
S
slzhou 已提交
31 32 33 34 35 36 37 38 39 40 41
    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);
    }
S
shenglian zhou 已提交
42
  }
43
  //to simulate actual processing delay by udf
S
shenglian zhou 已提交
44 45 46
#ifdef LINUX
  usleep(1 * 1000);   // usleep takes sleep time in us (1 millionth of a second)
#endif
47
#ifdef WINDOWS
S
shenglian zhou 已提交
48
  Sleep(1);
49
#endif
S
shenglian zhou 已提交
50 51
  return 0;
}