fix: add function not implemented error

This commit is contained in:
slzhou 2023-03-01 15:37:08 +08:00
parent 844a083033
commit 2b566dabc7
4 changed files with 33 additions and 16 deletions

View File

@ -80,10 +80,6 @@ typedef struct SUdfInterBuf {
} SUdfInterBuf; } SUdfInterBuf;
typedef void *UdfcFuncHandle; typedef void *UdfcFuncHandle;
// dynamic lib init and destroy
typedef int32_t (*TUdfInitFunc)();
typedef int32_t (*TUdfDestroyFunc)();
#define UDF_MEMORY_EXP_GROWTH 1.5 #define UDF_MEMORY_EXP_GROWTH 1.5
#define NBIT (3u) #define NBIT (3u)
#define BitPos(_n) ((_n) & ((1 << NBIT) - 1)) #define BitPos(_n) ((_n) & ((1 << NBIT) - 1))
@ -252,6 +248,10 @@ static FORCE_INLINE int32_t udfColDataSet(SUdfColumn *pColumn, uint32_t currentR
return 0; return 0;
} }
// dynamic lib init and destroy for C UDF
typedef int32_t (*TUdfInitFunc)();
typedef int32_t (*TUdfDestroyFunc)();
typedef int32_t (*TUdfScalarProcFunc)(SUdfDataBlock *block, SUdfColumn *resultCol); typedef int32_t (*TUdfScalarProcFunc)(SUdfDataBlock *block, SUdfColumn *resultCol);
typedef int32_t (*TUdfAggStartFunc)(SUdfInterBuf *buf); typedef int32_t (*TUdfAggStartFunc)(SUdfInterBuf *buf);

View File

@ -712,6 +712,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_UDF_INVALID_BUFSIZE TAOS_DEF_ERROR_CODE(0, 0x2909) #define TSDB_CODE_UDF_INVALID_BUFSIZE TAOS_DEF_ERROR_CODE(0, 0x2909)
#define TSDB_CODE_UDF_INVALID_OUTPUT_TYPE TAOS_DEF_ERROR_CODE(0, 0x290A) #define TSDB_CODE_UDF_INVALID_OUTPUT_TYPE TAOS_DEF_ERROR_CODE(0, 0x290A)
#define TSDB_CODE_UDF_SCRIPT_NOT_SUPPORTED TAOS_DEF_ERROR_CODE(0, 0x290B) #define TSDB_CODE_UDF_SCRIPT_NOT_SUPPORTED TAOS_DEF_ERROR_CODE(0, 0x290B)
#define TSDB_CODE_UDF_FUNC_NOT_IMPLEMENTED TAOS_DEF_ERROR_CODE(0, 0x290C)
// sml // sml
#define TSDB_CODE_SML_INVALID_PROTOCOL_TYPE TAOS_DEF_ERROR_CODE(0, 0x3000) #define TSDB_CODE_SML_INVALID_PROTOCOL_TYPE TAOS_DEF_ERROR_CODE(0, 0x3000)

View File

@ -96,8 +96,15 @@ int32_t udfdCPluginUdfInit(SScriptUdfInfo *udf, void **pUdfCtx) {
strncat(mergeFuncName, mergeSuffix, strlen(mergeSuffix)); strncat(mergeFuncName, mergeSuffix, strlen(mergeSuffix));
uv_dlsym(&udfCtx->lib, mergeFuncName, (void **)(&udfCtx->aggMergeFunc)); uv_dlsym(&udfCtx->lib, mergeFuncName, (void **)(&udfCtx->aggMergeFunc));
} }
int32_t code = 0;
if (udfCtx->initFunc) { if (udfCtx->initFunc) {
(udfCtx->initFunc)(); // TODO: handle init call return error
code = (udfCtx->initFunc)();
if (code != 0) {
uv_dlclose(&udfCtx->lib);
taosMemoryFree(udfCtx);
return code;
}
} }
*pUdfCtx = udfCtx; *pUdfCtx = udfCtx;
return 0; return 0;
@ -105,26 +112,30 @@ int32_t udfdCPluginUdfInit(SScriptUdfInfo *udf, void **pUdfCtx) {
int32_t udfdCPluginUdfDestroy(void *udfCtx) { int32_t udfdCPluginUdfDestroy(void *udfCtx) {
SUdfCPluginCtx *ctx = udfCtx; SUdfCPluginCtx *ctx = udfCtx;
int32_t code = 0;
if (ctx->destroyFunc) { if (ctx->destroyFunc) {
(ctx->destroyFunc)(); code = (ctx->destroyFunc)();
} }
uv_dlclose(&ctx->lib); uv_dlclose(&ctx->lib);
taosMemoryFree(ctx); taosMemoryFree(ctx);
return 0; return code;
} }
int32_t udfdCPluginUdfScalarProc(SUdfDataBlock *block, SUdfColumn *resultCol, void *udfCtx) { int32_t udfdCPluginUdfScalarProc(SUdfDataBlock *block, SUdfColumn *resultCol, void *udfCtx) {
SUdfCPluginCtx *ctx = udfCtx; SUdfCPluginCtx *ctx = udfCtx;
if (ctx->scalarProcFunc) { if (ctx->scalarProcFunc) {
ctx->scalarProcFunc(block, resultCol); return ctx->scalarProcFunc(block, resultCol);
} else {
return TSDB_CODE_UDF_FUNC_NOT_IMPLEMENTED;
} }
return 0;
} }
int32_t udfdCPluginUdfAggStart(SUdfInterBuf *buf, void *udfCtx) { int32_t udfdCPluginUdfAggStart(SUdfInterBuf *buf, void *udfCtx) {
SUdfCPluginCtx *ctx = udfCtx; SUdfCPluginCtx *ctx = udfCtx;
if (ctx->aggStartFunc) { if (ctx->aggStartFunc) {
ctx->aggStartFunc(buf); return ctx->aggStartFunc(buf);
} else {
return TSDB_CODE_UDF_FUNC_NOT_IMPLEMENTED;
} }
return 0; return 0;
} }
@ -132,24 +143,28 @@ int32_t udfdCPluginUdfAggStart(SUdfInterBuf *buf, void *udfCtx) {
int32_t udfdCPluginUdfAggProc(SUdfDataBlock *block, SUdfInterBuf *interBuf, SUdfInterBuf *newInterBuf, void *udfCtx) { int32_t udfdCPluginUdfAggProc(SUdfDataBlock *block, SUdfInterBuf *interBuf, SUdfInterBuf *newInterBuf, void *udfCtx) {
SUdfCPluginCtx *ctx = udfCtx; SUdfCPluginCtx *ctx = udfCtx;
if (ctx->aggProcFunc) { if (ctx->aggProcFunc) {
ctx->aggProcFunc(block, interBuf, newInterBuf); return ctx->aggProcFunc(block, interBuf, newInterBuf);
} else {
return TSDB_CODE_UDF_FUNC_NOT_IMPLEMENTED;
} }
return 0;
} }
int32_t udfdCPluginUdfAggMerge(SUdfInterBuf *inputBuf1, SUdfInterBuf *inputBuf2, SUdfInterBuf *outputBuf, int32_t udfdCPluginUdfAggMerge(SUdfInterBuf *inputBuf1, SUdfInterBuf *inputBuf2, SUdfInterBuf *outputBuf,
void *udfCtx) { void *udfCtx) {
SUdfCPluginCtx *ctx = udfCtx; SUdfCPluginCtx *ctx = udfCtx;
if (ctx->aggMergeFunc) { if (ctx->aggMergeFunc) {
ctx->aggMergeFunc(inputBuf1, inputBuf2, outputBuf); return ctx->aggMergeFunc(inputBuf1, inputBuf2, outputBuf);
} else {
return TSDB_CODE_UDF_FUNC_NOT_IMPLEMENTED;
} }
return 0;
} }
int32_t udfdCPluginUdfAggFinish(SUdfInterBuf *buf, SUdfInterBuf *resultData, void *udfCtx) { int32_t udfdCPluginUdfAggFinish(SUdfInterBuf *buf, SUdfInterBuf *resultData, void *udfCtx) {
SUdfCPluginCtx *ctx = udfCtx; SUdfCPluginCtx *ctx = udfCtx;
if (ctx->aggFinishFunc) { if (ctx->aggFinishFunc) {
ctx->aggFinishFunc(buf, resultData); return ctx->aggFinishFunc(buf, resultData);
} else {
return TSDB_CODE_UDF_FUNC_NOT_IMPLEMENTED;
} }
return 0; return 0;
} }

View File

@ -583,6 +583,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_UDF_NO_FUNC_HANDLE, "udf no function han
TAOS_DEFINE_ERROR(TSDB_CODE_UDF_INVALID_BUFSIZE, "udf invalid bufsize") TAOS_DEFINE_ERROR(TSDB_CODE_UDF_INVALID_BUFSIZE, "udf invalid bufsize")
TAOS_DEFINE_ERROR(TSDB_CODE_UDF_INVALID_OUTPUT_TYPE, "udf invalid output type") TAOS_DEFINE_ERROR(TSDB_CODE_UDF_INVALID_OUTPUT_TYPE, "udf invalid output type")
TAOS_DEFINE_ERROR(TSDB_CODE_UDF_SCRIPT_NOT_SUPPORTED, "udf program language not supported") TAOS_DEFINE_ERROR(TSDB_CODE_UDF_SCRIPT_NOT_SUPPORTED, "udf program language not supported")
TAOS_DEFINE_ERROR(TSDB_CODE_UDF_FUNC_NOT_IMPLEMENTED, "udf function not implemented")
//schemaless //schemaless
TAOS_DEFINE_ERROR(TSDB_CODE_SML_INVALID_PROTOCOL_TYPE, "Invalid line protocol type") TAOS_DEFINE_ERROR(TSDB_CODE_SML_INVALID_PROTOCOL_TYPE, "Invalid line protocol type")