From 2e266771b15b0ea962e934596789ed9e0884199c Mon Sep 17 00:00:00 2001 From: slzhou Date: Tue, 14 Feb 2023 13:08:32 +0800 Subject: [PATCH] fix: dispatch to udf by language type and udf name --- source/libs/function/src/udfd.c | 36 +++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c index f50ce71b50..1f6f7902a4 100644 --- a/source/libs/function/src/udfd.c +++ b/source/libs/function/src/udfd.c @@ -329,7 +329,7 @@ int32_t udfdLoadSharedLib(char *libPath, uv_lib_t *pLib, const char *funcName[], void udfdInitializePythonPlugin(SUdfScriptPlugin *plugin) { plugin->scriptType = TSDB_FUNC_SCRIPT_PYTHON; - sprintf("%s", plugin->libPath, "libtaosudf_py.so"); + sprintf(plugin->libPath, "%s", "libtaosudf_py.so"); plugin->libLoaded = false; const char *funcName[MAX_NUM_PLUGIN_FUNCS] = {"open", "close", "udfInit", "udfDestroy", "udfScalarProc", "udfAggStart", @@ -347,17 +347,41 @@ void udfdInitializePythonPlugin(SUdfScriptPlugin *plugin) { return; } +void udfdDeinitCPlugin(SUdfScriptPlugin *plugin) { + return; +} + +void udfdDeinitPythonPlugin(SUdfScriptPlugin *plugin) { + if (plugin->libLoaded) { + uv_dlclose(&plugin->lib); + plugin->libLoaded = false; + } +} + void udfdInitScriptPlugins() { - SUdfScriptPlugin *plugins = taosMemoryCalloc(2, sizeof(SUdfScriptPlugin)); - // Initialize c language plugin - udfdInitializeCPlugin(plugins + 0); + SUdfScriptPlugin *plugin = NULL; + + // Initialize c plugin + plugin = taosMemoryCalloc(1, sizeof(SUdfScriptPlugin)); + udfdInitializeCPlugin(plugin); + global.scriptPlugins[TSDB_FUNC_SCRIPT_BIN_LIB] = plugin; + // Initialize python plugin - udfdInitializePythonPlugin(plugins + 1); + plugin = taosMemoryCalloc(1, sizeof(SUdfScriptPlugin)); + udfdInitializePythonPlugin(plugin); + global.scriptPlugins[TSDB_FUNC_SCRIPT_PYTHON] = plugin; return; } void udfdDeinitScriptPlugins() { - + SUdfScriptPlugin *plugin = NULL; + plugin = global.scriptPlugins[TSDB_FUNC_SCRIPT_PYTHON]; + udfdDeinitPythonPlugin(plugin); + taosMemoryFree(plugin); + + plugin = global.scriptPlugins[TSDB_FUNC_SCRIPT_BIN_LIB]; + udfdDeinitCPlugin(plugin); + taosMemoryFree(plugin); return; } -- GitLab