[ https://issues.apache.org/jira/browse/CALCITE-3463?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16964566#comment-16964566 ]
Wang Yanlin commented on CALCITE-3463: -------------------------------------- [~yunpengn] I think you can update your sql like this {noformat} select * from emp left join (select emp2.id, emp3.name from emp2 inner join emp3 on emp2.id = emp3.id) t on emp.id = t.id; {noformat} so that you can keep the brackets > Parse SQL Query - Non-query expression encountered in illegal context > --------------------------------------------------------------------- > > Key: CALCITE-3463 > URL: https://issues.apache.org/jira/browse/CALCITE-3463 > Project: Calcite > Issue Type: Improvement > Components: core > Affects Versions: 1.21.0 > Environment: OS: macOS Catalina 10.15 > Java: java 12.0.2 2019-07-16 > Reporter: Yunpeng Niu > Priority: Major > Attachments: image-2019-10-31-21-11-41-225.png > > > I tried to ask calcite-core to parse the following SQL query: > > {code:java} > final SqlParser.Config parserConfig = SqlParser.configBuilder() > .setConformance(SqlConformanceEnum.MYSQL_5) > .setLex(Lex.MYSQL) > .build(); > String query = "SELECT * FROM departments d INNER JOIN (dept_manager m INNER > JOIN employees e ON m.emp_no = e.emp_no) ON d.dept_no = m.dept_no"; > SqlParser.create(query, parserConfig).parseQuery(); > {code} > > > But there is the following exception: > {noformat} > Exception in thread "main" org.apache.calcite.sql.parser.SqlParseException: > Non-query expression encountered in illegal contextException in thread "main" > org.apache.calcite.sql.parser.SqlParseException: Non-query expression > encountered in illegal context at > org.apache.calcite.sql.parser.impl.SqlParserImpl.convertException(SqlParserImpl.java:362) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.normalizeException(SqlParserImpl.java:147) > at > org.apache.calcite.sql.parser.SqlParser.handleException(SqlParser.java:148) > at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:163) at > org.apache.calcite.Runner.main(Runner.java:60)Caused by: > org.apache.calcite.runtime.CalciteException: Non-query expression encountered > in illegal context at > java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native > Method) at > java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) > at > java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) > at > java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) > at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481) > at > org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:463) > at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:572) at > org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:835) at > org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:820) at > org.apache.calcite.sql.parser.impl.SqlParserImpl.checkNonQueryExpression(SqlParserImpl.java:306) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.Expression3(SqlParserImpl.java:13780) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.Expression2b(SqlParserImpl.java:13449) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.Expression2(SqlParserImpl.java:13490) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.Expression(SqlParserImpl.java:13421) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.LeafQueryOrExpr(SqlParserImpl.java:13398) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.QueryOrExpr(SqlParserImpl.java:12874) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.OrderedQueryOrExpr(SqlParserImpl.java:478) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.ParenthesizedExpression(SqlParserImpl.java:639) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.TableRef2(SqlParserImpl.java:8145) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.TableRef(SqlParserImpl.java:8068) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.FromClause(SqlParserImpl.java:7969) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.SqlSelect(SqlParserImpl.java:3722) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.LeafQuery(SqlParserImpl.java:604) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.LeafQueryOrExpr(SqlParserImpl.java:13404) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.QueryOrExpr(SqlParserImpl.java:12874) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.OrderedQueryOrExpr(SqlParserImpl.java:478) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.SqlStmt(SqlParserImpl.java:3626) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.SqlStmtEof(SqlParserImpl.java:3664) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.parseSqlStmtEof(SqlParserImpl.java:194) > at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:161) > ... 1 more > Process finished with exit code 1 > {noformat} > > I have tried to run the above query in MySQL database and I am sure it is > valid syntax. Can anyone help to explain why the above exception is thrown? > Thanks. And how should I fix this? -- This message was sent by Atlassian Jira (v8.3.4#803005)