tudf.h 3.3 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 25
#undef malloc
#define malloc malloc
#undef free
#define free free
#undef realloc
#define alloc alloc
#include <taosudf.h>
S
shenglian zhou 已提交
26 27

#include <stdbool.h>
H
Hongze Cheng 已提交
28
#include <stdint.h>
S
slzhou 已提交
29
#include "function.h"
H
Hongze Cheng 已提交
30
#include "tcommon.h"
S
shenglian zhou 已提交
31
#include "tdatablock.h"
H
Hongze Cheng 已提交
32
#include "tmsg.h"
S
shenglian zhou 已提交
33

34 35 36 37
#ifdef __cplusplus
extern "C" {
#endif

S
slzhou 已提交
38
#define UDF_LISTEN_PIPE_NAME_LEN 32
39 40 41 42 43
#ifdef _WIN32
#define UDF_LISTEN_PIPE_NAME_PREFIX "\\\\?\\pipe\\udfd.sock"
#else
#define UDF_LISTEN_PIPE_NAME_PREFIX ".udfd.sock."
#endif
44
#define UDF_DNODE_ID_ENV_NAME "DNODE_ID"
S
slzhou 已提交
45

H
Hongze Cheng 已提交
46
// low level APIs
47 48 49 50 51 52 53
/**
 * setup udf
 * @param udf, in
 * @param funcHandle, out
 * @return error code
 */
int32_t doSetupUdf(char udfName[], UdfcFuncHandle *funcHandle);
S
slzhou 已提交
54
// output: interBuf
55
int32_t doCallUdfAggInit(UdfcFuncHandle handle, SUdfInterBuf *interBuf);
S
slzhou 已提交
56 57
// input: block, state
// output: newState
58
int32_t doCallUdfAggProcess(UdfcFuncHandle handle, SSDataBlock *block, SUdfInterBuf *state, SUdfInterBuf *newState);
S
shenglian zhou 已提交
59 60
// input: interBuf
// output: resultData
61
int32_t doCallUdfAggFinalize(UdfcFuncHandle handle, SUdfInterBuf *interBuf, SUdfInterBuf *resultData);
S
slzhou 已提交
62 63
// input: interbuf1, interbuf2
// output: resultBuf
H
Hongze Cheng 已提交
64 65
int32_t doCallUdfAggMerge(UdfcFuncHandle handle, SUdfInterBuf *interBuf1, SUdfInterBuf *interBuf2,
                          SUdfInterBuf *resultBuf);
S
shenglian zhou 已提交
66 67
// input: block
// output: resultData
68
int32_t doCallUdfScalarFunc(UdfcFuncHandle handle, SScalarParam *input, int32_t numOfCols, SScalarParam *output);
69 70 71 72 73
/**
 * tearn down udf
 * @param handle
 * @return
 */
74
int32_t doTeardownUdf(UdfcFuncHandle handle);
75

S
slzhou 已提交
76 77
void freeUdfInterBuf(SUdfInterBuf *buf);

H
Hongze Cheng 已提交
78 79 80
// high level APIs
bool    udfAggGetEnv(struct SFunctionNode *pFunc, SFuncExecEnv *pEnv);
bool    udfAggInit(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo *pResultCellInfo);
S
shenglian zhou 已提交
81
int32_t udfAggProcess(struct SqlFunctionCtx *pCtx);
H
Hongze Cheng 已提交
82
int32_t udfAggFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock *pBlock);
83 84

int32_t callUdfScalarFunc(char *udfName, SScalarParam *input, int32_t numOfCols, SScalarParam *output);
S
slzhou 已提交
85

86
int32_t cleanUpUdfs();
87

H
Haojun Liao 已提交
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// udf api
/**
 * create udfd proxy, called once in process that call doSetupUdf/callUdfxxx/doTeardownUdf
 * @return error code
 */
int32_t udfcOpen();

/**
 * destroy udfd proxy
 * @return error code
 */
int32_t udfcClose();

/**
 * start udfd that serves udf function invocation under dnode startDnodeId
 * @param startDnodeId
 * @return
 */
int32_t udfStartUdfd(int32_t startDnodeId);
/**
 * stop udfd
 * @return
 */
int32_t udfStopUdfd();

114 115 116 117 118 119
/**
 * get udfd pid
 *
 */
 int32_t udfGetUdfdPid(int32_t* pUdfdPid);

120 121 122 123
#ifdef __cplusplus
}
#endif

124
#endif  // TDENGINE_TUDF_H