Q1: org.apache.flink.table.api.SqlParserException: SQL parse failed. Non-query expression encountered in illegal context
问题详情:老夫在FlinkSQL中执行一个SQL语句,出现了SQL的解析错误。老夫在检查了SQL语句在Phoenix上的运行后发现也跑不通,看了下异常,发现笔者的表中某一字段类型是varchar,而笔者对这个字段做了SUM操作,修正后,在Phoenix中是可以运行,但是在FlinkSQL中还是有问题。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Exception in thread "main" org.apache.flink.table.api.SqlParserException: SQL parse failed. Non-query expression encountered in illegal context
at org.apache.flink.table.calcite.FlinkPlannerImpl.parse(FlinkPlannerImpl.scala:99)
at org.apache.flink.table.api.internal.TableEnvImpl.sqlQuery(TableEnvImpl.scala:428)
at com.ci123.cidata.platform.flink.outline.module.operator.BSql.getTableActual(BSql.java:39)
at com.ci123.cidata.platform.flink.outline.module.operator.BSql.process(BSql.java:27)
at com.ci123.cidata.platform.flink.outline.module.operator.BSql.process(BSql.java:21)
at com.ci123.cidata.platform.flink.common.framework.base.LinearModule.processMany(LinearModule.java:15)
at com.ci123.cidata.platform.flink.common.framework.base.SubMultiDataModule.processMany(SubMultiDataModule.java:33)
at com.ci123.cidata.platform.flink.common.framework.base.MultiDataModule.process(MultiDataModule.java:33)
at com.ci123.cidata.platform.flink.common.framework.base.Job.createTopology(Job.java:121)
at com.ci123.cidata.platform.flink.common.framework.base.Job.start(Job.java:37)
at com.ci123.cidata.platform.flink.Main.lambda$main$2(Main.java:14)
at com.ci123.cidata.platform.flink.util.Parameters.execute(Parameters.java:51)
at com.ci123.cidata.platform.flink.Main.main(Main.java:11)
Caused by: org.apache.calcite.sql.parser.SqlParseException: Non-query expression encountered in illegal context
at org.apache.flink.sql.parser.impl.FlinkSqlParserImpl.convertException(FlinkSqlParserImpl.java:368)
at org.apache.flink.sql.parser.impl.FlinkSqlParserImpl.normalizeException(FlinkSqlParserImpl.java:167)
at org.apache.calcite.sql.parser.SqlParser.handleException(SqlParser.java:147)
at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:162)
at org.apache.calcite.sql.parser.SqlParser.parseStmt(SqlParser.java:187)
at org.apache.flink.table.calcite.FlinkPlannerImpl.parse(FlinkPlannerImpl.scala:95)
... 12 more

A1: 既然是SqlParserException错误,就肯定是Sql语句有问题了,可能是Sql里面的关键字写错了,也有可能是语法错了。找出来就好了。