tudf.h 3.9 KB
Newer Older
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_TUDF_H
#define TDENGINE_TUDF_H

19 20 21 22
#ifdef __cplusplus
extern "C" {
#endif

23 24
//======================================================================================
//begin API to taosd and qworker
25 26 27 28 29
enum {
  UDFC_CODE_STOPPING = -1,
  UDFC_CODE_RESTARTING = -2,
};

30 31 32 33 34 35 36 37 38 39 40 41
/**
 * start udf dameon service
 * @return error code
 */
int32_t startUdfService();

/**
 * stop udf dameon service
 * @return error code
 */
int32_t stopUdfService();

42 43 44 45 46 47 48 49 50 51
enum {
  TSDB_UDF_TYPE_SCALAR = 0,
  TSDB_UDF_TYPE_AGGREGATE = 1
};

enum {
  TSDB_UDF_SCRIPT_BIN_LIB = 0,
  TSDB_UDF_SCRIPT_LUA = 1,
};

52 53
typedef struct SUdfInfo {
  char   *udfName;        // function name
54 55
  int32_t udfType;    // scalar function or aggregate function
  int8_t    scriptType;
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
  char *path;

  int8_t  resType;     // result type
  int16_t resBytes;    // result byte
  int32_t bufSize;     //interbuf size

} SUdfInfo;

typedef void *UdfHandle;

/**
 * setup udf
 * @param udf, in
 * @param handle, out
 * @return error code
 */
int32_t setupUdf(SUdfInfo* udf, UdfHandle *handle);

74

75
enum {
76 77 78 79
  TSDB_UDF_STEP_NORMAL = 0,
  TSDB_UDF_STEP_MERGE,
  TSDb_UDF_STEP_FINALIZE,
  TSDB_UDF_STEP_MAX_NUM
80
};
81 82 83 84 85 86 87 88 89 90 91 92
/**
 * call udf
 * @param handle udf handle
 * @param step
 * @param state
 * @param stateSize
 * @param input
 * @param newstate
 * @param newStateSize
 * @param output
 * @return error code
 */
93

94
//TODO: must change the following after metadata flow and data flow between qworker and udfd is well defined
95
typedef struct SUdfDataBlock {
96 97
  char* data;
  int32_t size;
98
} SUdfDataBlock;
99

100 101
int32_t callUdf(UdfHandle handle, int8_t step, char *state, int32_t stateSize, SUdfDataBlock input, char **newstate,
                int32_t *newStateSize, SUdfDataBlock *output);
102

103 104 105 106 107 108 109 110 111
/**
 * tearn down udf
 * @param handle
 * @return
 */
int32_t teardownUdf(UdfHandle handle);

// end API to taosd and qworker
//=============================================================================================================================
112 113
// TODO: Must change
// begin API to UDF writer.
114 115 116

// script

117 118 119 120 121 122 123
//typedef int32_t (*scriptInitFunc)(void* pCtx);
//typedef void (*scriptNormalFunc)(void* pCtx, char* data, int16_t iType, int16_t iBytes, int32_t numOfRows,
//                                 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);
//typedef void (*scriptMergeFunc)(void* pCtx, char* data, int32_t numOfRows, char* dataOutput, int32_t* numOfOutput);
//typedef void (*scriptDestroyFunc)(void* pCtx);
124 125

// dynamic lib
126 127 128 129 130 131
typedef int32_t (*TUdfInitFunc)();
typedef void (*TUdfDestroyFunc)();

typedef void (*TUdfFunc)(int8_t step,
                         char *state, int32_t stateSize, SUdfDataBlock input,
                         char **newstate, int32_t *newStateSize, SUdfDataBlock *output);
132

133 134
//typedef void (*udfMergeFunc)(char *data, int32_t numOfRows, char *dataOutput, int32_t* numOfOutput);
//typedef void (*udfFinalizeFunc)(char* state, int32_t stateSize, SUdfDataBlock *output);
135 136 137

// end API to UDF writer
//=======================================================================================================================
138

139 140 141 142
#ifdef __cplusplus
}
#endif

143
#endif  // TDENGINE_TUDF_H