欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

Flink任务报CannothavemorethanoneexecuteorexecuteAsynccallinasingleenvironment

时间:2023-04-17

问题描述:

使用Flink 1.12开发的任务在本地IDEA中可以正常运行,发布到集群上报如下错误:

java.util.concurrent.CompletionException: org.apache.flink.client.deployment.application.ApplicationExecutionException: Could not execute application

at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:292)

....

Caused by: org.apache.flink.client.deployment.ApplicationExecutionException: Could not execute application

Caused by: org.apache.flink.client.program.ProgramInvocationException: The main method caused an error: Failed to execute sql

at org.apache.flink.client.program.PackageProgram.callMainMethod(PackageProgram.java:219)

....

Caused by: org.apache.flink.table.api.TableException: Failed to execute sql

Caused by: org.apache.flink.util.FlinkRuntimeException: Cannot have more than one execute() or executeAsync() call in a single enviroment

....

解决方法:

排查发现程序中使用遍历sql集合一条一条调用tEnv.executeSql(sql)的方式执行sql,如:

for(String sql: sqlList) {

      tEnv.executeSql(sql);

}

改成使用sqlUpdate、execute解决:

for(String sql: sqlList) {

      tEnv.sqlUpdate(sql);

}

tEnv.execute("jobName")

需要注意的是updateSql方法已经标记为废弃,在新版的1.14+ Flink中已经没有这个方法了,需要使用createStatementSet执行多条Sql

 

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。