[jira] [Commented] (CALCITE-2152) SQL parser unable to parse SQL with nested joins produced by RelToSqlConverter

2021-10-18 Thread Julian Hyde (Jira)


[ 
https://issues.apache.org/jira/browse/CALCITE-2152?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17430166#comment-17430166
 ] 

Julian Hyde commented on CALCITE-2152:
--

I meant that the algorithm (inserting a Project between the Joins, and 
therefore forcing a sub-query) was a sound one for fixing a bug in 
RelToSqlConverter. I wasn't saying you should fix it, and what it's worth, I 
don't have time to fix it or time to help you. But hopefully someone does. My 
words were encouragement for that person.

> SQL parser unable to parse SQL with nested joins produced by RelToSqlConverter
> --
>
> Key: CALCITE-2152
> URL: https://issues.apache.org/jira/browse/CALCITE-2152
> Project: Calcite
>  Issue Type: Bug
>Reporter: Samuel Waggoner
>Priority: Major
>
> I created this test case in RelToSqlConverterTest:
> {code:java}
> @Test
> public void testNestedJoin() {
> final String query = "select *"
> + "from \"sales_fact_1997\" "
> + "inner join (select * from \"customer\""
> + "inner join \"employee\" on (\"customer\".\"city\" = 
> \"employee\".\"store_id\") ) AS \"customer_employee\""
> + "on (\"sales_fact_1997\".\"store_id\" = \"customer_employee\".\"city\")";
> String result = sql(query).exec();
> System.out.println(result);
> sql(result).exec();
> }
> {code}
> result looks like this:
> {code:java}
> SELECT *
>  FROM "foodmart"."sales_fact_1997"
>  INNER JOIN ("foodmart"."customer"
>  INNER JOIN "foodmart"."employee" ON "customer"."city" = 
> "employee"."store_id") ON "sales_fact_1997"."store_id" = 
> "customer"."city"{code}
>  
> The resulting stack trace:
>  
> {code:java}
> java.lang.RuntimeException: org.apache.calcite.sql.parser.SqlParseException: 
> Non-query expression encountered in illegal context
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverterTest$Sql.exec(RelToSqlConverterTest.java:2420)
>  at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverterTest.testNestedJoin(RelToSqlConverterTest.java:2314)
>  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>  at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>  at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  at java.lang.reflect.Method.invoke(Method.java:498)
>  at 
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
>  at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
>  at 
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
>  at 
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
>  at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
>  at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
>  at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
>  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
>  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
>  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
>  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
>  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
>  at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
>  at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
>  at 
> com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
>  at 
> com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
>  at 
> com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
>  at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
>  Caused by: org.apache.calcite.sql.parser.SqlParseException: Non-query 
> expression encountered in illegal context
>  at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.convertException(SqlParserImpl.java:350)
>  at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.normalizeException(SqlParserImpl.java:131)
>  at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:138)
>  at org.apache.calcite.sql.parser.SqlParser.parseStmt(SqlParser.java:163)
>  at org.apache.calcite.prepare.PlannerImpl.parse(PlannerImpl.java:179)
>  at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverterTest$Sql.exec(RelToSqlConverterTest.java:2407)
>  ... 23 more
>  Caused by: org.apache.calcite.runtime.CalciteException: Non-query expression 
> encountered in illegal context
>  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>  at 
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
>  at 
> 

[jira] [Commented] (CALCITE-2152) SQL parser unable to parse SQL with nested joins produced by RelToSqlConverter

2021-10-18 Thread Ian Bertolacci (Jira)


[ 
https://issues.apache.org/jira/browse/CALCITE-2152?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17430085#comment-17430085
 ] 

Ian Bertolacci commented on CALCITE-2152:
-

[~julianhyde] Just to be clear, what specifically is a good idea?

I'm open to being assigned this issue.
However, if the appropriate approach involves "correctly" using the 
SqlImplementor interface, I'm gonna need some help. 
On the other hand, if inserting a shim projection node will suffice, I can have 
a PR up reasonably quickly.

> SQL parser unable to parse SQL with nested joins produced by RelToSqlConverter
> --
>
> Key: CALCITE-2152
> URL: https://issues.apache.org/jira/browse/CALCITE-2152
> Project: Calcite
>  Issue Type: Bug
>Reporter: Samuel Waggoner
>Priority: Major
>
> I created this test case in RelToSqlConverterTest:
> {code:java}
> @Test
> public void testNestedJoin() {
> final String query = "select *"
> + "from \"sales_fact_1997\" "
> + "inner join (select * from \"customer\""
> + "inner join \"employee\" on (\"customer\".\"city\" = 
> \"employee\".\"store_id\") ) AS \"customer_employee\""
> + "on (\"sales_fact_1997\".\"store_id\" = \"customer_employee\".\"city\")";
> String result = sql(query).exec();
> System.out.println(result);
> sql(result).exec();
> }
> {code}
> result looks like this:
> {code:java}
> SELECT *
>  FROM "foodmart"."sales_fact_1997"
>  INNER JOIN ("foodmart"."customer"
>  INNER JOIN "foodmart"."employee" ON "customer"."city" = 
> "employee"."store_id") ON "sales_fact_1997"."store_id" = 
> "customer"."city"{code}
>  
> The resulting stack trace:
>  
> {code:java}
> java.lang.RuntimeException: org.apache.calcite.sql.parser.SqlParseException: 
> Non-query expression encountered in illegal context
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverterTest$Sql.exec(RelToSqlConverterTest.java:2420)
>  at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverterTest.testNestedJoin(RelToSqlConverterTest.java:2314)
>  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>  at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>  at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  at java.lang.reflect.Method.invoke(Method.java:498)
>  at 
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
>  at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
>  at 
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
>  at 
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
>  at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
>  at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
>  at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
>  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
>  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
>  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
>  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
>  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
>  at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
>  at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
>  at 
> com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
>  at 
> com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
>  at 
> com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
>  at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
>  Caused by: org.apache.calcite.sql.parser.SqlParseException: Non-query 
> expression encountered in illegal context
>  at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.convertException(SqlParserImpl.java:350)
>  at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.normalizeException(SqlParserImpl.java:131)
>  at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:138)
>  at org.apache.calcite.sql.parser.SqlParser.parseStmt(SqlParser.java:163)
>  at org.apache.calcite.prepare.PlannerImpl.parse(PlannerImpl.java:179)
>  at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverterTest$Sql.exec(RelToSqlConverterTest.java:2407)
>  ... 23 more
>  Caused by: org.apache.calcite.runtime.CalciteException: Non-query expression 
> encountered in illegal context
>  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>  at 
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
>  at 
> 

[jira] [Commented] (CALCITE-2152) SQL parser unable to parse SQL with nested joins produced by RelToSqlConverter

2021-10-14 Thread Julian Hyde (Jira)


[ 
https://issues.apache.org/jira/browse/CALCITE-2152?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17429120#comment-17429120
 ] 

Julian Hyde commented on CALCITE-2152:
--

[~ian.bertolacci], That's a good idea.

> SQL parser unable to parse SQL with nested joins produced by RelToSqlConverter
> --
>
> Key: CALCITE-2152
> URL: https://issues.apache.org/jira/browse/CALCITE-2152
> Project: Calcite
>  Issue Type: Bug
>Reporter: Samuel Waggoner
>Priority: Major
>
> I created this test case in RelToSqlConverterTest:
> {code:java}
> @Test
> public void testNestedJoin() {
> final String query = "select *"
> + "from \"sales_fact_1997\" "
> + "inner join (select * from \"customer\""
> + "inner join \"employee\" on (\"customer\".\"city\" = 
> \"employee\".\"store_id\") ) AS \"customer_employee\""
> + "on (\"sales_fact_1997\".\"store_id\" = \"customer_employee\".\"city\")";
> String result = sql(query).exec();
> System.out.println(result);
> sql(result).exec();
> }
> {code}
> result looks like this:
> {code:java}
> SELECT *
>  FROM "foodmart"."sales_fact_1997"
>  INNER JOIN ("foodmart"."customer"
>  INNER JOIN "foodmart"."employee" ON "customer"."city" = 
> "employee"."store_id") ON "sales_fact_1997"."store_id" = 
> "customer"."city"{code}
>  
> The resulting stack trace:
>  
> {code:java}
> java.lang.RuntimeException: org.apache.calcite.sql.parser.SqlParseException: 
> Non-query expression encountered in illegal context
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverterTest$Sql.exec(RelToSqlConverterTest.java:2420)
>  at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverterTest.testNestedJoin(RelToSqlConverterTest.java:2314)
>  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>  at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>  at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  at java.lang.reflect.Method.invoke(Method.java:498)
>  at 
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
>  at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
>  at 
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
>  at 
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
>  at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
>  at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
>  at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
>  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
>  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
>  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
>  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
>  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
>  at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
>  at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
>  at 
> com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
>  at 
> com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
>  at 
> com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
>  at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
>  Caused by: org.apache.calcite.sql.parser.SqlParseException: Non-query 
> expression encountered in illegal context
>  at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.convertException(SqlParserImpl.java:350)
>  at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.normalizeException(SqlParserImpl.java:131)
>  at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:138)
>  at org.apache.calcite.sql.parser.SqlParser.parseStmt(SqlParser.java:163)
>  at org.apache.calcite.prepare.PlannerImpl.parse(PlannerImpl.java:179)
>  at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverterTest$Sql.exec(RelToSqlConverterTest.java:2407)
>  ... 23 more
>  Caused by: org.apache.calcite.runtime.CalciteException: Non-query expression 
> encountered in illegal context
>  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>  at 
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
>  at 
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
>  at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
>  at 
> org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:463)
>  at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:572)
>  at 

[jira] [Commented] (CALCITE-2152) SQL parser unable to parse SQL with nested joins produced by RelToSqlConverter

2021-10-14 Thread Ian Bertolacci (Jira)


[ 
https://issues.apache.org/jira/browse/CALCITE-2152?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17429029#comment-17429029
 ] 

Ian Bertolacci commented on CALCITE-2152:
-

We solved this our RelToSqlConverter extending class by cloning the parent join 
and inserting a projection between it and an RHS join:
{code}
override def visit(join: Join): Result = {
if (join.getRight.isInstanceOf[Join]) {
  super.visit(
join.copy(
  join.getTraitSet,
  join.getCondition,
  join.getLeft,
  new LogicalProject(
join.getCluster,
join.getTraitSet,
join.getHints,
join.getRight,
// Construct projection of all expressions from the rhs join
join.getRight.getRowType.getFieldList.asScala.map(field => new 
RexInputRef(field.getIndex, field.getType)).asJava,
join.getRight.getRowType
  ),
  join.getJoinType,
  join.isSemiJoinDone
)
  )
} else {
  super.visit(join)
}
  }
{code}
We tried to do it "correctly" by constructing a proper Result object, but found 
it too difficult. 
Hopefully someone else can figure out how do it the right way.

It would be nice if this functionality could be fixed in Calcite's 
RelToSqlConverter.

> SQL parser unable to parse SQL with nested joins produced by RelToSqlConverter
> --
>
> Key: CALCITE-2152
> URL: https://issues.apache.org/jira/browse/CALCITE-2152
> Project: Calcite
>  Issue Type: Bug
>Reporter: Samuel Waggoner
>Priority: Major
>
> I created this test case in RelToSqlConverterTest:
> {code:java}
> @Test
> public void testNestedJoin() {
> final String query = "select *"
> + "from \"sales_fact_1997\" "
> + "inner join (select * from \"customer\""
> + "inner join \"employee\" on (\"customer\".\"city\" = 
> \"employee\".\"store_id\") ) AS \"customer_employee\""
> + "on (\"sales_fact_1997\".\"store_id\" = \"customer_employee\".\"city\")";
> String result = sql(query).exec();
> System.out.println(result);
> sql(result).exec();
> }
> {code}
> result looks like this:
> {code:java}
> SELECT *
>  FROM "foodmart"."sales_fact_1997"
>  INNER JOIN ("foodmart"."customer"
>  INNER JOIN "foodmart"."employee" ON "customer"."city" = 
> "employee"."store_id") ON "sales_fact_1997"."store_id" = 
> "customer"."city"{code}
>  
> The resulting stack trace:
>  
> {code:java}
> java.lang.RuntimeException: org.apache.calcite.sql.parser.SqlParseException: 
> Non-query expression encountered in illegal context
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverterTest$Sql.exec(RelToSqlConverterTest.java:2420)
>  at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverterTest.testNestedJoin(RelToSqlConverterTest.java:2314)
>  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>  at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>  at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  at java.lang.reflect.Method.invoke(Method.java:498)
>  at 
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
>  at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
>  at 
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
>  at 
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
>  at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
>  at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
>  at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
>  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
>  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
>  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
>  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
>  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
>  at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
>  at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
>  at 
> com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
>  at 
> com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
>  at 
> com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
>  at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
>  Caused by: org.apache.calcite.sql.parser.SqlParseException: Non-query 
> expression encountered in illegal context
>  at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.convertException(SqlParserImpl.java:350)
>  at 
> 

[jira] [Commented] (CALCITE-2152) SQL parser unable to parse SQL with nested joins produced by RelToSqlConverter

2018-01-29 Thread Julian Hyde (JIRA)

[ 
https://issues.apache.org/jira/browse/CALCITE-2152?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16344364#comment-16344364
 ] 

Julian Hyde commented on CALCITE-2152:
--

You are hitting a known limitation to the parser, see CALCITE-35. We would like 
to fix this, but it has proven hard.

A workaround might be to generate "(SELECT FROM x JOIN y ON ...) AS xy" rather 
than "(x JOIN y ON ...)". The effect is slightly different, because in the 
former the columns all belong to one table alias "xy", and in the latter they 
belong to two aliases "x" and "y".

> SQL parser unable to parse SQL with nested joins produced by RelToSqlConverter
> --
>
> Key: CALCITE-2152
> URL: https://issues.apache.org/jira/browse/CALCITE-2152
> Project: Calcite
>  Issue Type: Bug
>Reporter: Samuel Waggoner
>Assignee: Julian Hyde
>Priority: Major
>
> I created this test case in RelToSqlConverterTest:
> {code:java}
> @Test
> public void testNestedJoin() {
> final String query = "select *"
> + "from \"sales_fact_1997\" "
> + "inner join (select * from \"customer\""
> + "inner join \"employee\" on (\"customer\".\"city\" = 
> \"employee\".\"store_id\") ) AS \"customer_employee\""
> + "on (\"sales_fact_1997\".\"store_id\" = \"customer_employee\".\"city\")";
> String result = sql(query).exec();
> System.out.println(result);
> sql(result).exec();
> }
> {code}
> result looks like this:
> {code:java}
> SELECT *
>  FROM "foodmart"."sales_fact_1997"
>  INNER JOIN ("foodmart"."customer"
>  INNER JOIN "foodmart"."employee" ON "customer"."city" = 
> "employee"."store_id") ON "sales_fact_1997"."store_id" = 
> "customer"."city"{code}
>  
> The resulting stack trace:
>  
> {code:java}
> java.lang.RuntimeException: org.apache.calcite.sql.parser.SqlParseException: 
> Non-query expression encountered in illegal context
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverterTest$Sql.exec(RelToSqlConverterTest.java:2420)
>  at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverterTest.testNestedJoin(RelToSqlConverterTest.java:2314)
>  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>  at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>  at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  at java.lang.reflect.Method.invoke(Method.java:498)
>  at 
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
>  at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
>  at 
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
>  at 
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
>  at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
>  at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
>  at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
>  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
>  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
>  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
>  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
>  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
>  at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
>  at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
>  at 
> com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
>  at 
> com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
>  at 
> com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
>  at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
>  Caused by: org.apache.calcite.sql.parser.SqlParseException: Non-query 
> expression encountered in illegal context
>  at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.convertException(SqlParserImpl.java:350)
>  at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.normalizeException(SqlParserImpl.java:131)
>  at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:138)
>  at org.apache.calcite.sql.parser.SqlParser.parseStmt(SqlParser.java:163)
>  at org.apache.calcite.prepare.PlannerImpl.parse(PlannerImpl.java:179)
>  at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverterTest$Sql.exec(RelToSqlConverterTest.java:2407)
>  ... 23 more
>  Caused by: org.apache.calcite.runtime.CalciteException: Non-query expression 
> encountered in illegal context
>  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>  at 
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
>  at 
>