diff --git a/include/libs/function/taosudf.h b/include/libs/function/taosudf.h index 4e33bf633cafc2fff0dadf045e5224effe6f949e..1ef4f59b2c6cff3a1fe05fa6880e8d0c2d0915f9 100644 --- a/include/libs/function/taosudf.h +++ b/include/libs/function/taosudf.h @@ -261,6 +261,10 @@ typedef int32_t (*TUdfAggMergeFunc)(SUdfInterBuf *inputBuf1, SUdfInterBuf *input typedef int32_t (*TUdfAggFinishFunc)(SUdfInterBuf *buf, SUdfInterBuf *resultData); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +typedef struct SScriptUdfEnvItem{ + char *name; + char *value; +} SScriptUdfEnvItem; typedef enum EUdfFuncType { UDF_FUNC_TYPE_SCALAR = 1, @@ -291,8 +295,8 @@ typedef int32_t (*TScriptUdfInitFunc)(SScriptUdfInfo *info, void **pUdfCtx); typedef int32_t (*TScriptUdfDestoryFunc)(void *udfCtx); // the following function is for open/close script plugin. -typedef int32_t (*TScriptOpenFunc)(void *scriptCtx); -typedef int32_t (*TScriptCloseFunc)(void *scriptCtx); +typedef int32_t (*TScriptOpenFunc)(SScriptUdfEnvItem* items, int numItems); +typedef int32_t (*TScriptCloseFunc)(); #ifdef __cplusplus } diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c index d2a61d74e2df3ce2fc0b77bd11c1323850ee0098..ed5f87647f0a54c1b4f40fd213933d4751573730 100644 --- a/source/libs/function/src/udfd.c +++ b/source/libs/function/src/udfd.c @@ -48,9 +48,9 @@ typedef struct SUdfCPluginCtx { TUdfDestroyFunc destroyFunc; } SUdfCPluginCtx; -int32_t udfdCPluginOpen(void *scriptCtx) { return 0; } +int32_t udfdCPluginOpen(SScriptUdfEnvItem *items, int numItems) { return 0; } -int32_t udfdCPluginClose(void *scriptCtx) { return 0; } +int32_t udfdCPluginClose() { return 0; } int32_t udfdCPluginUdfInit(SScriptUdfInfo *udf, void **pUdfCtx) { int32_t err = 0; @@ -308,6 +308,9 @@ void udfdInitializeCPlugin(SUdfScriptPlugin *plugin) { plugin->udfAggProcFunc = udfdCPluginUdfAggProc; plugin->udfAggMergeFunc = udfdCPluginUdfAggMerge; plugin->udfAggFinishFunc = udfdCPluginUdfAggFinish; + + SScriptUdfEnvItem items[0]; + plugin->openFunc(items, 0); return; } @@ -343,19 +346,45 @@ void udfdInitializePythonPlugin(SUdfScriptPlugin *plugin) { fnError("can not load python plugin. lib path %s", plugin->libPath); return; } + if (plugin->openFunc) { + SScriptUdfEnvItem items[] ={{"PYTHONPATH", tsUdfdLdLibPath}}; + plugin->openFunc(items, 1); + } plugin->libLoaded = true; return; } void udfdDeinitCPlugin(SUdfScriptPlugin *plugin) { + if (plugin->closeFunc) { + plugin->closeFunc(); + } + plugin->openFunc = NULL; + plugin->closeFunc = NULL; + plugin->udfInitFunc = NULL; + plugin->udfDestroyFunc = NULL; + plugin->udfScalarProcFunc = NULL; + plugin->udfAggStartFunc = NULL; + plugin->udfAggProcFunc = NULL; + plugin->udfAggMergeFunc = NULL; + plugin->udfAggFinishFunc = NULL; return; } void udfdDeinitPythonPlugin(SUdfScriptPlugin *plugin) { + plugin->closeFunc(); uv_dlclose(&plugin->lib); if (plugin->libLoaded) { plugin->libLoaded = false; } + plugin->openFunc = NULL; + plugin->closeFunc = NULL; + plugin->udfInitFunc = NULL; + plugin->udfDestroyFunc = NULL; + plugin->udfScalarProcFunc = NULL; + plugin->udfAggStartFunc = NULL; + plugin->udfAggProcFunc = NULL; + plugin->udfAggMergeFunc = NULL; + plugin->udfAggFinishFunc = NULL; } void udfdInitScriptPlugins() {