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

#include "uv.h"
wafwerar's avatar
wafwerar 已提交
6
#include "os.h"
S
shenglian zhou 已提交
7
#include "tudf.h"
S
shenglian zhou 已提交
8
#include "tdatablock.h"
S
shenglian zhou 已提交
9 10

int main(int argc, char *argv[]) {
11 12
  UdfcHandle udfc;
  udfcOpen(1, &udfc);
S
shenglian zhou 已提交
13 14 15 16 17 18 19 20 21 22 23
    uv_sleep(1000);
    char path[256] = {0};
    size_t cwdSize = 256;
    int err = uv_cwd(path, &cwdSize);
    if (err != 0) {
        fprintf(stderr, "err cwd: %s\n", uv_strerror(err));
	    return err;
    }
    fprintf(stdout, "current working directory:%s\n", path);
    strcat(path, "/libudf1.so");

24
    UdfcFuncHandle handle;
25
    SEpSet epSet;
26
    setupUdf(udfc, "udf1", &epSet, &handle);
S
shenglian zhou 已提交
27

S
shenglian zhou 已提交
28 29 30 31 32
    SSDataBlock block = {0};
    SSDataBlock* pBlock = &block;
    pBlock->pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData));
    pBlock->info.numOfCols = 1;
    pBlock->info.rows = 4;
S
slzhou 已提交
33
    char data[16] = {0};
S
slzhou 已提交
34
    char bitmap[4] = {0};
S
shenglian zhou 已提交
35 36 37 38 39
    for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) {
      SColumnInfoData colInfo = {0};
      colInfo.info.type = TSDB_DATA_TYPE_INT;
      colInfo.info.bytes = sizeof(int32_t);
      colInfo.info.colId = 1;
S
slzhou 已提交
40 41
      colInfo.pData = data;
      colInfo.nullbitmap = bitmap;
S
shenglian zhou 已提交
42 43 44 45 46 47
      for (int32_t j = 0; j < pBlock->info.rows; ++j) {
        colDataAppendInt32(&colInfo, j, &j);
      }
      taosArrayPush(pBlock->pDataBlock, &colInfo);
    }

S
slzhou 已提交
48 49 50 51 52 53 54 55
    SScalarParam input = {0};
    input.numOfRows = pBlock->info.rows;
    input.columnData = taosArrayGet(pBlock->pDataBlock, 0);
    SScalarParam output = {0};
    callUdfScalarFunc(handle, &input, 1 , &output);

    SColumnInfoData *col = output.columnData;
    for (int32_t i = 0; i < output.numOfRows; ++i) {
S
slzhou 已提交
56 57
      fprintf(stderr, "%d\t%d\n" , i, *(int32_t*)(col->pData + i *sizeof(int32_t)));
    }
S
shenglian zhou 已提交
58 59
    teardownUdf(handle);

60
    udfcClose(udfc);
S
shenglian zhou 已提交
61
}