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

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

7 8 9 10
#undef malloc
#define malloc malloc
#undef free
#define free free
S
slzhou 已提交
11

S
slzhou 已提交
12
int32_t udf1_init() {
S
shenglian zhou 已提交
13 14 15
  return 0;
}

S
slzhou 已提交
16
int32_t udf1_destroy() {
S
shenglian zhou 已提交
17
  return 0;
S
shenglian zhou 已提交
18
}
S
shenglian zhou 已提交
19

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

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

S
shenglian zhou 已提交
43 44
  return 0;
}