Apache Flink 1.11无法在SQL函数DDL中使用Python UDF



根据这个汇合页面:

https://cwiki.apache.org/confluence/display/FLINK/FLIP-106%3A+Support+Python+UDF+in+SQL+Function+DDL

Flink 1.11中的python-udf可用于SQL函数中。

我去了这里的flink文档:

https://ci.apache.org/projects/flink/flink-docs-stable/dev/table/sqlClient.html

并在终端上尝试此操作,然后使用以下参数启动sql客户端.sh

$ sql-client.sh embedded --pyExecutable /Users/jonathanfigueroa/opt/anaconda3/bin/python --pyFiles /Users/jonathanfigueroa/Desktop/pyflink/inference/test1.py

然后:

> Create Temporary System Function func1 as 'test1.func1' Language PYTHON;
[INFO] Function has been created. 

当我尝试时:

> Select func1(str) From (VALUES ("Name1", "Name2", "Name3"));
[ERROR] Could not execute SQL statement. Reason:
java.lang.IllegalStateException: Instantiating python function 'test1.func1' failed.

我试着在每一个单独的组合.zip, .py中使用:-pyarch,--pyArchives, -pyexec,--pyExecutable, -pyfs,--pyFiles,并且总是得到相同的结果。

顺便说一句,我的python文件看起来像这样:

def func1(s):
return s;

我缺什么了吗?

诚挚的问候,

Jonathan

python UDF应该用"udf";pyflink.table.udf中的decorator,如下所示:

from pyflink.table.types import DataTypes
from pyflink.table.udf import udf
@udf(input_types=[DataTypes.INT()], result_type=DataTypes.INT())
def add_one(a):
return a + 1

在启动sql客户端时,需要加载flink python jar,如下所示:

$ cd $FLINK_HOME/bin
$ ./start-cluster.sh
$ ./sql-client.sh embedded -pyfs xxx.py -j ../opt/flink-python_2.11-1.11.0.jar

此外,您需要将taskmanager.memory.task.off-heap.size: 79mb添加到$FLINK_HOME/conf/flink-conf.yaml或其他可用于设置配置的文件(例如sql客户端环境文件(,否则在执行python udf:时会出错

[ERROR] Could not execute SQL statement. Reason:
org.apache.flink.table.api.TableException: The configured Task Off-Heap Memory 0 bytes is less than the least required Python worker Memory 79 mb. The Task Off-Heap Memory can be configured using the configuration key'taskmanager.memory .task.off-heap.size'.

最佳,
Wei

相关内容

  • 没有找到相关文章

最新更新