udf1.c 1.2 KB
Newer Older
S
shenglian zhou 已提交
1 2 3
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
4
#include <unistd.h>
S
shenglian zhou 已提交
5

6
#include "taosudf.h"
S
shenglian zhou 已提交
7

S
slzhou 已提交
8

wafwerar's avatar
wafwerar 已提交
9
DLL_EXPORT int32_t udf1_init() {
S
shenglian zhou 已提交
10 11 12
  return 0;
}

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

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

S
shenglian zhou 已提交
24 25 26
  SUdfColumnData *resultData = &resultCol->colData;
  resultData->numOfRows = block->numOfRows;
  for (int32_t i = 0; i < resultData->numOfRows; ++i) {
S
slzhou 已提交
27 28 29 30 31 32 33 34 35 36 37
    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 已提交
38
  }
39 40 41 42 43
  //to simulate actual processing delay by udf
#ifdef WINDOWS
  HANDLE timer;
  LARGE_INTEGER interval;
  interval.QuadPart = (10 * 1000);
S
shenglian zhou 已提交
44

45 46 47 48 49 50 51
  timer = CreateWaitableTimer(NULL, TRUE, NULL);
  SetWaitableTimer(timer, &interval, 0, NULL, NULL, 0);
  WaitForSingleObject(timer, INFINITE);
  CloseHandle(timer);
#else
  usleep(1000);
#endif
S
shenglian zhou 已提交
52 53
  return 0;
}