qUdf.h 2.9 KB
Newer Older
H
Haojun Liao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef TDENGINE_QUDF_H
#define TDENGINE_QUDF_H

D
dapan1121 已提交
19
enum { TSDB_UDF_FUNC_NORMAL = 0, TSDB_UDF_FUNC_INIT, TSDB_UDF_FUNC_FINALIZE, TSDB_UDF_FUNC_MERGE, TSDB_UDF_FUNC_DESTROY, TSDB_UDF_FUNC_MAX_NUM };
D
dapan1121 已提交
20 21 22 23 24 25 26 27 28



typedef struct SUdfInit{
 int32_t maybe_null;       /* 1 if function can return NULL */
 uint32_t decimals;     /* for real functions */
 uint64_t length;       /* For string functions */
 char  *ptr;            /* free pointer for function data */
 int32_t const_item;       /* 0 if result is independent of arguments */
Y
yihaoDeng 已提交
29 30 31 32

 // script like lua/javascript
 void* script_ctx;
 void (*destroyCtxFunc)(void *script_ctx);
D
dapan1121 已提交
33 34 35
} SUdfInit;


H
Haojun Liao 已提交
36 37
typedef struct SUdfInfo {
  int32_t functionId;  // system assigned function id
38
  int32_t funcType;    // scalar function or aggregate function
H
Haojun Liao 已提交
39 40 41
  int8_t  resType;     // result type
  int16_t resBytes;    // result byte
  int32_t contLen;     // content length
D
dapan1121 已提交
42
  int32_t bufSize;     //interbuf size
H
Haojun Liao 已提交
43
  char   *name;        // function name
D
dapan1121 已提交
44 45
  void   *handle;      // handle loaded in mem
  void   *funcs[TSDB_UDF_FUNC_MAX_NUM];     // function ptr
Y
yihaoDeng 已提交
46 47 48 49 50

  // for script like lua/javascript only
  int    isScript;
  void   *pScriptCtx;

D
dapan1121 已提交
51
  SUdfInit init;
D
dapan1121 已提交
52 53
  char *content;
  char *path;
H
Haojun Liao 已提交
54 55
} SUdfInfo;

Y
yihaoDeng 已提交
56 57 58 59
//script 

typedef int32_t (*scriptInitFunc)(void *pCtx);
typedef void (*scriptNormalFunc)(void *pCtx, char* data, int16_t iType, int16_t iBytes, int32_t numOfRows,
Y
yihaoDeng 已提交
60 61
                                 int64_t* ptList, int64_t key, char* dataOutput, char* tsOutput, int32_t* numOfOutput, int16_t oType, int16_t oBytes);
typedef void (*scriptFinalizeFunc)(void *pCtx, int64_t key, char* dataOutput, int32_t* numOfOutput);
Y
yihaoDeng 已提交
62 63 64 65
typedef void (*scriptMergeFunc)(void *pCtx, char* data, int32_t numOfRows, char* dataOutput, int32_t* numOfOutput);
typedef void (*scriptDestroyFunc)(void* pCtx);

// dynamic lib
D
dapan1121 已提交
66 67
typedef void (*udfNormalFunc)(char* data, int16_t itype, int16_t iBytes, int32_t numOfRows, int64_t* ts, char* dataOutput, char* interBuf,
  char* tsOutput, int32_t* numOfOutput, int16_t oType, int16_t oBytes, SUdfInit* buf);
D
dapan1121 已提交
68
typedef int32_t (*udfInitFunc)(SUdfInit* data);
D
dapan1121 已提交
69
typedef void (*udfFinalizeFunc)(char* dataOutput, char *interBuf, int32_t* numOfOutput, SUdfInit* buf);
D
dapan1121 已提交
70
typedef void (*udfMergeFunc)(char* data, int32_t numOfRows, char* dataOutput, int32_t* numOfOutput, SUdfInit* buf);
D
dapan1121 已提交
71
typedef void (*udfDestroyFunc)(SUdfInit* buf);
D
dapan1121 已提交
72 73


H
Haojun Liao 已提交
74
#endif  // TDENGINE_QUDF_H