feat: script open function accept env item
This commit is contained in:
parent
48bcec4631
commit
898bd0ed33
|
@ -261,6 +261,10 @@ typedef int32_t (*TUdfAggMergeFunc)(SUdfInterBuf *inputBuf1, SUdfInterBuf *input
|
||||||
typedef int32_t (*TUdfAggFinishFunc)(SUdfInterBuf *buf, SUdfInterBuf *resultData);
|
typedef int32_t (*TUdfAggFinishFunc)(SUdfInterBuf *buf, SUdfInterBuf *resultData);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
typedef struct SScriptUdfEnvItem{
|
||||||
|
char *name;
|
||||||
|
char *value;
|
||||||
|
} SScriptUdfEnvItem;
|
||||||
|
|
||||||
typedef enum EUdfFuncType {
|
typedef enum EUdfFuncType {
|
||||||
UDF_FUNC_TYPE_SCALAR = 1,
|
UDF_FUNC_TYPE_SCALAR = 1,
|
||||||
|
@ -291,8 +295,8 @@ typedef int32_t (*TScriptUdfInitFunc)(SScriptUdfInfo *info, void **pUdfCtx);
|
||||||
typedef int32_t (*TScriptUdfDestoryFunc)(void *udfCtx);
|
typedef int32_t (*TScriptUdfDestoryFunc)(void *udfCtx);
|
||||||
|
|
||||||
// the following function is for open/close script plugin.
|
// the following function is for open/close script plugin.
|
||||||
typedef int32_t (*TScriptOpenFunc)(void *scriptCtx);
|
typedef int32_t (*TScriptOpenFunc)(SScriptUdfEnvItem* items, int numItems);
|
||||||
typedef int32_t (*TScriptCloseFunc)(void *scriptCtx);
|
typedef int32_t (*TScriptCloseFunc)();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,9 +48,9 @@ typedef struct SUdfCPluginCtx {
|
||||||
TUdfDestroyFunc destroyFunc;
|
TUdfDestroyFunc destroyFunc;
|
||||||
} SUdfCPluginCtx;
|
} 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 udfdCPluginUdfInit(SScriptUdfInfo *udf, void **pUdfCtx) {
|
||||||
int32_t err = 0;
|
int32_t err = 0;
|
||||||
|
@ -308,6 +308,9 @@ void udfdInitializeCPlugin(SUdfScriptPlugin *plugin) {
|
||||||
plugin->udfAggProcFunc = udfdCPluginUdfAggProc;
|
plugin->udfAggProcFunc = udfdCPluginUdfAggProc;
|
||||||
plugin->udfAggMergeFunc = udfdCPluginUdfAggMerge;
|
plugin->udfAggMergeFunc = udfdCPluginUdfAggMerge;
|
||||||
plugin->udfAggFinishFunc = udfdCPluginUdfAggFinish;
|
plugin->udfAggFinishFunc = udfdCPluginUdfAggFinish;
|
||||||
|
|
||||||
|
SScriptUdfEnvItem items[0];
|
||||||
|
plugin->openFunc(items, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,19 +346,45 @@ void udfdInitializePythonPlugin(SUdfScriptPlugin *plugin) {
|
||||||
fnError("can not load python plugin. lib path %s", plugin->libPath);
|
fnError("can not load python plugin. lib path %s", plugin->libPath);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (plugin->openFunc) {
|
||||||
|
SScriptUdfEnvItem items[] ={{"PYTHONPATH", tsUdfdLdLibPath}};
|
||||||
|
plugin->openFunc(items, 1);
|
||||||
|
}
|
||||||
plugin->libLoaded = true;
|
plugin->libLoaded = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void udfdDeinitCPlugin(SUdfScriptPlugin *plugin) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void udfdDeinitPythonPlugin(SUdfScriptPlugin *plugin) {
|
void udfdDeinitPythonPlugin(SUdfScriptPlugin *plugin) {
|
||||||
|
plugin->closeFunc();
|
||||||
uv_dlclose(&plugin->lib);
|
uv_dlclose(&plugin->lib);
|
||||||
if (plugin->libLoaded) {
|
if (plugin->libLoaded) {
|
||||||
plugin->libLoaded = false;
|
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() {
|
void udfdInitScriptPlugins() {
|
||||||
|
|
Loading…
Reference in New Issue