udf1.c 873 字节
Newer Older
S
shenglian zhou 已提交
1 2 3 4
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

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

S
slzhou 已提交
7

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

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

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

S
shenglian zhou 已提交
23 24 25
  SUdfColumnData *resultData = &resultCol->colData;
  resultData->numOfRows = block->numOfRows;
  for (int32_t i = 0; i < resultData->numOfRows; ++i) {
S
slzhou 已提交
26 27 28 29 30 31 32 33 34 35 36
    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 已提交
37
  }
S
shenglian zhou 已提交
38

S
shenglian zhou 已提交
39 40
  return 0;
}