TDengine/include/libs/function/tudf.h

174 lines
5.9 KiB
C
Raw Normal View History

/*
* 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
#undef malloc
#define malloc malloc
#undef free
#define free free
#undef realloc
#define alloc alloc
#include <taosudf.h>
2022-04-14 11:29:41 +00:00
#include <stdbool.h>
2022-10-13 03:09:43 +00:00
#include <stdint.h>
2022-04-22 02:10:14 +00:00
#include "function.h"
2022-10-13 03:09:43 +00:00
#include "tcommon.h"
2022-05-05 11:03:05 +00:00
#include "tdatablock.h"
2022-10-13 03:09:43 +00:00
#include "tmsg.h"
2022-04-14 11:29:41 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2022-04-20 09:46:29 +00:00
#define UDF_LISTEN_PIPE_NAME_LEN 32
#ifdef _WIN32
2025-04-09 10:41:43 +00:00
#define UDF_LISTEN_PIPE_NAME_PREFIX "\\\\?\\pipe\\" CUS_PROMPT "udf.sock"
#else
2025-04-09 10:41:43 +00:00
#define UDF_LISTEN_PIPE_NAME_PREFIX "." CUS_PROMPT "udf.sock."
#endif
#define UDF_DNODE_ID_ENV_NAME "DNODE_ID"
2022-04-20 09:46:29 +00:00
2024-07-27 10:33:08 +00:00
#define TAOS_UV_LIB_ERROR_RET(ret) \
do { \
if (0 != ret) { \
terrno = TSDB_CODE_UDF_UV_EXEC_FAILURE; \
return TSDB_CODE_UDF_UV_EXEC_FAILURE; \
} \
} while(0)
#define TAOS_UV_CHECK_ERRNO(CODE) \
do { \
if (0 != CODE) { \
terrln = __LINE__; \
terrno = (CODE); \
goto _exit; \
} \
} while (0)
2024-11-11 01:23:02 +00:00
#define TAOS_UDF_CHECK_PTR_RCODE(...) \
do { \
const void *ptrs[] = {__VA_ARGS__}; \
for (int i = 0; i < sizeof(ptrs) / sizeof(ptrs[0]); ++i) { \
if (ptrs[i] == NULL) { \
2025-04-09 10:41:43 +00:00
fnError("udf %dth parameter invalid, NULL PTR.line:%d", i, __LINE__); \
2024-11-11 01:23:02 +00:00
return TSDB_CODE_INVALID_PARA; \
} \
} \
} while (0)
#define TAOS_UDF_CHECK_PTR_RVOID(...) \
do { \
const void *ptrs[] = {__VA_ARGS__}; \
for (int i = 0; i < sizeof(ptrs) / sizeof(ptrs[0]); ++i) { \
if (ptrs[i] == NULL) { \
2025-04-09 10:41:43 +00:00
fnError("udf %dth parameter invalid, NULL PTR.line:%d", i, __LINE__); \
2024-11-11 01:23:02 +00:00
return; \
} \
} \
} while (0)
2024-11-11 03:04:11 +00:00
#define TAOS_UDF_CHECK_CONDITION(o, code) \
do { \
if ((o) == false) { \
fnError("Condition not met.line:%d", __LINE__); \
return code; \
} \
} while (0)
2024-07-27 10:33:08 +00:00
2022-10-13 03:09:43 +00:00
// low level APIs
/**
* setup udf
* @param udf, in
* @param funcHandle, out
* @return error code
*/
int32_t doSetupUdf(char udfName[], UdfcFuncHandle *funcHandle);
2022-04-17 07:07:11 +00:00
// output: interBuf
int32_t doCallUdfAggInit(UdfcFuncHandle handle, SUdfInterBuf *interBuf);
2022-04-17 07:07:11 +00:00
// input: block, state
// output: newState
int32_t doCallUdfAggProcess(UdfcFuncHandle handle, SSDataBlock *block, SUdfInterBuf *state, SUdfInterBuf *newState);
2022-04-13 11:45:33 +00:00
// input: interBuf
// output: resultData
int32_t doCallUdfAggFinalize(UdfcFuncHandle handle, SUdfInterBuf *interBuf, SUdfInterBuf *resultData);
2022-04-15 04:19:22 +00:00
// input: interbuf1, interbuf2
// output: resultBuf
2024-12-19 07:43:24 +00:00
// udf todo: aggmerge
// int32_t doCallUdfAggMerge(UdfcFuncHandle handle, SUdfInterBuf *interBuf1, SUdfInterBuf *interBuf2,
// SUdfInterBuf *resultBuf);
2022-04-13 11:45:33 +00:00
// input: block
// output: resultData
int32_t doCallUdfScalarFunc(UdfcFuncHandle handle, SScalarParam *input, int32_t numOfCols, SScalarParam *output);
/**
* tearn down udf
* @param handle
* @return
*/
int32_t doTeardownUdf(UdfcFuncHandle handle);
2022-05-17 04:03:37 +00:00
void freeUdfInterBuf(SUdfInterBuf *buf);
2022-10-13 03:09:43 +00:00
// high level APIs
bool udfAggGetEnv(struct SFunctionNode *pFunc, SFuncExecEnv *pEnv);
int32_t udfAggInit(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo *pResultCellInfo);
2022-04-25 07:44:40 +00:00
int32_t udfAggProcess(struct SqlFunctionCtx *pCtx);
2022-10-13 03:09:43 +00:00
int32_t udfAggFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock *pBlock);
int32_t callUdfScalarFunc(char *udfName, SScalarParam *input, int32_t numOfCols, SScalarParam *output);
2022-05-15 23:47:56 +00:00
int32_t cleanUpUdfs();
2022-11-30 13:26:27 +00:00
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// udf api
/**
2025-03-06 14:20:52 +00:00
* create taosudf proxy, called once in process that call doSetupUdf/callUdfxxx/doTeardownUdf
2022-11-30 13:26:27 +00:00
* @return error code
*/
int32_t udfcOpen();
/**
2025-03-06 14:20:52 +00:00
* destroy taosudf proxy
2022-11-30 13:26:27 +00:00
* @return error code
*/
int32_t udfcClose();
/**
2025-03-06 14:20:52 +00:00
* start taosudf that serves udf function invocation under dnode startDnodeId
2022-11-30 13:26:27 +00:00
* @param startDnodeId
* @return
*/
int32_t udfStartUdfd(int32_t startDnodeId);
/**
2025-03-06 14:20:52 +00:00
* stop taosudf
2022-11-30 13:26:27 +00:00
* @return
*/
2024-07-27 10:33:08 +00:00
void udfStopUdfd();
2022-11-30 13:26:27 +00:00
/**
2025-03-06 14:20:52 +00:00
* get taosudf pid
*
*/
2024-07-27 10:33:08 +00:00
// int32_t udfGetUdfdPid(int32_t* pUdfdPid);
#ifdef __cplusplus
}
#endif
#endif // TDENGINE_TUDF_H