我希望有一种方式可以通过MySQL存储过程调用Python。
因此,我想知道是否可以使用Python编写UDF,并从MySQL中调用。
如果不可能,那么我能用什么替代方法实现这个功能呢?
我希望有一种方式可以通过MySQL存储过程调用Python。
因此,我想知道是否可以使用Python编写UDF,并从MySQL中调用。
如果不可能,那么我能用什么替代方法实现这个功能呢?
myfunc
的简单UDF字符串函数,共享对象将具有以下函数:// initialize state when 'myfunc' is loaded.
my_bool myfunc_init(UDF_INIT *initid, UDF_ARGS *args, ...)
// call myfunc, this would need to translate the args, invoke the
// python function, then return the string, may need to create and cache
// python sub-interpreters on the fly, etc
char *myfunc(UDF_INIT *initid, UDF_ARGS *args, ...)
// clean up the state when 'myfunc' is unloaded.
void myfunc_deinit(UDF_INIT *initid);
由于可能会有多个线程同时运行您的UDF,因此您需要找到一种方法,在单个函数调用的上下文中高效地创建和缓存子解释器,或者安全地在多个线程之间重复使用单个解释器(使用锁可能会使速度变慢,不可接受)。