tudf.h 3.8 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 25 26 27 28 29 30 31 32 33 34 35 36
//======================================================================================
//begin API to taosd and qworker
/**
 * start udf dameon service
 * @return error code
 */
int32_t startUdfService();

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

37 38 39 40 41 42 43 44 45 46
enum {
  TSDB_UDF_TYPE_SCALAR = 0,
  TSDB_UDF_TYPE_AGGREGATE = 1
};

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

47 48
typedef struct SUdfInfo {
  char   *udfName;        // function name
49 50
  int32_t udfType;    // scalar function or aggregate function
  int8_t    scriptType;
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
  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);

69

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

89
//TODO: must change the following after metadata flow and data flow between qworker and udfd is well defined
90
typedef struct SUdfDataBlock {
91 92
  char* data;
  int32_t size;
93
} SUdfDataBlock;
94

95 96
int32_t callUdf(UdfHandle handle, int8_t step, char *state, int32_t stateSize, SUdfDataBlock input, char **newstate,
                int32_t *newStateSize, SUdfDataBlock *output);
97

98 99 100 101 102 103 104 105 106
/**
 * tearn down udf
 * @param handle
 * @return
 */
int32_t teardownUdf(UdfHandle handle);

// end API to taosd and qworker
//=============================================================================================================================
107 108
// TODO: Must change
// begin API to UDF writer.
109 110 111

// script

112 113 114 115 116 117 118
//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);
119 120

// dynamic lib
121 122 123 124 125 126
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);
127

128 129
//typedef void (*udfMergeFunc)(char *data, int32_t numOfRows, char *dataOutput, int32_t* numOfOutput);
//typedef void (*udfFinalizeFunc)(char* state, int32_t stateSize, SUdfDataBlock *output);
130 131 132

// end API to UDF writer
//=======================================================================================================================
133

134 135 136 137
#ifdef __cplusplus
}
#endif

138
#endif  // TDENGINE_TUDF_H