Description
(nicetities first - great project and thanks all for the great work)
As per sql-92 grammar, the joined table can be wrapped in parenthesis but this is currently not supported in the Calcite grammar. A simple example is `select * from (table1 join table2 on 1=1)`. The error provided by Calcite is:
Non-query expression encountered in illegal context at org.apache.calcite.avatica.Helper.createException(Helper.java:56) at org.apache.calcite.avatica.Helper.createException(Helper.java:41) at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:163) at org.apache.calcite.avatica.AvaticaStatement.execute(AvaticaStatement.java:217) at org.apache.calcite.avatica.jdbc.JdbcMeta.prepareAndExecute(JdbcMeta.java:747) ... 20 common frames omitted Caused by: java.lang.RuntimeException: parse failed: Non-query expression encountered in illegal context at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:628) at org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:513) at org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:483) at org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:249) at org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:623) at org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675) at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156) ... 22 common frames omitted Caused by: org.apache.calcite.sql.parser.SqlParseException: Non-query expression encountered in illegal context at com.outsystems.datafabric.grammar.generated.SqlParserImpl.convertException(SqlParserImpl.java:381) at com.outsystems.datafabric.grammar.generated.SqlParserImpl.normalizeException(SqlParserImpl.java:154) at org.apache.calcite.sql.parser.SqlParser.handleException(SqlParser.java:140) at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:155) at org.apache.calcite.sql.parser.SqlParser.parseStmt(SqlParser.java:180) at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:624) ... 28 common frames omitted 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.newInstance(Constructor.java:490) at org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:506) at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:600)
The derivation is:
<from clause> = FROM <table reference> <from clause> = FROM <joined table> <from clause> = FROM <left paren> <joined table> <right paren> <from clause> = FROM <left paren> <qualified join> <right paren> <from clause> = FROM <left paren> <table reference> [ NATURAL ] [ <join type> ] JOIN <table reference> [ <join specification> ] <right paren>
I couldn't find a way to extend Calcite's default javacc grammar to support this syntax without having to replicate the whole file.
It would be great to either add support for this syntax (since Calcite aims to be sql92 compliant) OR provide an extension point for customisation.
I am not familiar enough with javacc to contribute with a quality solution though.
Attachments
Issue Links
- duplicates
-
CALCITE-35 Support parenthesized sub-clause in JOIN
- Closed