Flink任务报Cannot have more than one execute() or executeAsync() call in a single environment

问题描述:

使用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

Flink任务报Cannot have more than one execute() or executeAsync() call in a single environment_第1张图片

 

你可能感兴趣的:(Java,Spark,日志,flink,java,大数据,实时计算,实时数仓)