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 23 24
#ifdef __cplusplus
extern "C" {
#endif

#include "os.h"
#include "taoserror.h"
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#include "tcommon.h"

//======================================================================================
//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();

typedef struct SUdfInfo {
  char   *udfName;        // function name
  int32_t funcType;    // scalar function or aggregate function
  int8_t    isScript;
  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);

63

64
enum {
65 66 67 68
  TSDB_UDF_STEP_NORMAL = 0,
  TSDB_UDF_STEP_MERGE,
  TSDb_UDF_STEP_FINALIZE,
  TSDB_UDF_STEP_MAX_NUM
69
};
70 71 72 73 74 75 76 77 78 79 80 81
/**
 * call udf
 * @param handle udf handle
 * @param step
 * @param state
 * @param stateSize
 * @param input
 * @param newstate
 * @param newStateSize
 * @param output
 * @return error code
 */
82

83 84 85 86 87 88 89
typedef struct SUdfDataBlock {
  int16_t numOfCols;
  struct {
    char* data;
    int32_t length;
  } *colsData;
} SUdfDataBlock;
90

91 92
int32_t callUdf(UdfHandle handle, int8_t step, char *state, int32_t stateSize, SUdfDataBlock *input, char **newstate,
                int32_t *newStateSize, SUdfDataBlock **output);
93

94 95 96 97 98 99 100 101 102 103
/**
 * tearn down udf
 * @param handle
 * @return
 */
int32_t teardownUdf(UdfHandle handle);

// end API to taosd and qworker
//=============================================================================================================================
// begin API to UDF writer
104 105 106

// script

107 108 109 110 111 112 113
//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);
114 115

// dynamic lib
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
typedef int32_t (*udfInitFunc)();
typedef void (*udfDestroyFunc)();

typedef void (*udfNormalFunc)(char *state, int32_t stateSize, SUdfDataBlock input, char **newstate,
                              int32_t *newStateSize, SUdfDataBlock *output);
typedef void (*udfMergeFunc)(char* data, int32_t numOfRows, char* dataOutput, int32_t* numOfOutput);
typedef void (*udfFinalizeFunc)(char* state, int32_t stateSize, SUdfDataBlock *output);

// end API to UDF writer
//=======================================================================================================================
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
};
134

135 136 137 138
#ifdef __cplusplus
}
#endif

139
#endif  // TDENGINE_TUDF_H