背景
mac环境 flink 1.11.2 执行pyflink
flink run -py /Users/haozhang/from_hive_to_mysql.py
pyflink udf大概内容
@udf(input_types=[DataTypes.ARRAY(DataTypes.INT())], result_type=DataTypes.STRING())
def changeIntArrayToString(data):
return str(data)
t_env.execute_sql("select id,name,changeIntArrayToString(hobby) as hobby2 from hst1int").print()
报错
Caused by: java.io.IOException: Failed to execute the command: python -c
import pyflink;import
os;print(os.path.join(os.path.abspath(os.path.dirname(pyflink.__file__)),
'bin'))
output: Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named pyflink
原因分析
系统中有多个python执行环境,默认的系统中的执行环境不带pyflink ,所以提交指令带上本地执行器:
flink run -py /Users/haozhang/work/project/feature-operator/flink-operator/python_codes/examples/stream/from_hive_to_mysql.py -pyexec /Users/haozhang/opt/anaconda3/envs/feature-operator/bin/python
参考文档:http://apache-flink.147419.n8.nabble.com/python-udf-td7198.html
指定python执行环境后接着报错:
File "/Applications/flink-1.11.2/opt/python/pyflink.zip/pyflink/table/table_result.py", line 144, in print
File "/Applications/flink-1.11.2/opt/python/py4j-0.10.8.1-src.zip/py4j/java_gateway.py", line 1285, in __call__
File "/Applications/flink-1.11.2/opt/python/pyflink.zip/pyflink/util/exceptions.py", line 147, in deco
File "/Applications/flink-1.11.2/opt/python/py4j-0.10.8.1-src.zip/py4j/protocol.py", line 326, in get_return_value
py4j.protocol.Py4JJavaError: An error occurred while calling o132.print.
: java.lang.RuntimeException: Failed to fetch next result
at org.apache.flink.streaming.api.operators.collect.CollectResultIterator.nextResultFromFetcher(CollectResultIterator.java:92)
at org.apache.flink.streaming.api.operators.collect.CollectResultIterator.hasNext(CollectResultIterator.java:63)
at org.apache.flink.table.utils.PrintUtils.printAsTableauForm(PrintUtils.java:144)
at org.apache.flink.table.api.internal.TableResultImpl.print(TableResultImpl.java:98)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.flink.api.python.shaded.py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
at org.apache.flink.api.python.shaded.py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
at org.apache.flink.api.python.shaded.py4j.Gateway.invoke(Gateway.java:282)
at org.apache.flink.api.python.shaded.py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at org.apache.flink.api.python.shaded.py4j.commands.CallCommand.execute(CallCommand.java:79)
at org.apache.flink.api.python.shaded.py4j.GatewayConnection.run(GatewayConnection.java:238)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.IOException: Failed to fetch job execution result
at org.apache.flink.streaming.api.operators.collect.CollectResultFetcher.getAccumulatorResults(CollectResultFetcher.java:178)
at org.apache.flink.streaming.api.operators.collect.CollectResultFetcher.next(CollectResultFetcher.java:128)
at org.apache.flink.streaming.api.operators.collect.CollectResultIterator.nextResultFromFetcher(CollectResultIterator.java:89)
... 14 more
Caused by: java.util.concurrent.ExecutionException: org.apache.flink.client.program.ProgramInvocationException: Job failed (JobID: 935c9e49e1c012319c4bcaecd43e6d3a)
at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357)
at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1928)
at org.apache.flink.streaming.api.operators.collect.CollectResultFetcher.getAccumulatorResults(CollectResultFetcher.java:175)
... 16 more
Caused by: org.apache.flink.client.program.ProgramInvocationException: Job failed (JobID: 935c9e49e1c012319c4bcaecd43e6d3a)
at org.apache.flink.client