[ https://issues.apache.org/jira/browse/CALCITE-2153?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Samuel Waggoner updated CALCITE-2153: ------------------------------------- Description: I started working on a unit test in SqlParserTest (it's hard to predict exact output, so I just have a placeholder empty string for expectation right now). {code:java} @Test public void testInnerJoinOnSubqueryWithAggregation() { final String sql = "select *\n" + "from table1 \n" + "inner join (( \n" + " select * \n" + " from table2 ) \n" + " inner join ( \n" + " select * \n" + " from table3) \n" + " on table2.field1 = table3.field1) \n" + "on table1.field1 = table2.field1 \n"; sql(sql).ok(""); }{code} I believe this is valid SQL, but parsing fails with this exception {code:java} java.lang.RuntimeException: Error while parsing SQL: select * from table1 inner join (( select * from table2 ) inner join ( select * from table3) on table2.field1 = table3.field1) on table1.field1 = table2.field1 at org.apache.calcite.sql.parser.SqlParserTest$TesterImpl.parseStmtAndHandleEx(SqlParserTest.java:8201) at org.apache.calcite.sql.parser.SqlParserTest$TesterImpl.check(SqlParserTest.java:8186) at org.apache.calcite.sql.parser.SqlParserTest$Sql.ok(SqlParserTest.java:8384) at org.apache.calcite.sql.parser.SqlParserTest.testInnerJoinOnSubqueryWithAggregation(SqlParserTest.java:8156) 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: Encountered "inner" at line 6, column 3. Was expecting one of: ")" ... "ORDER" ... "LIMIT" ... "OFFSET" ... "FETCH" ... "UNION" ... "INTERSECT" ... "EXCEPT" ... "MINUS" ... "NOT" ... "IN" ... "<" ... "<=" ... ">" ... ">=" ... "=" ... "<>" ... "!=" ... "BETWEEN" ... "LIKE" ... "SIMILAR" ... "+" ... "-" ... "*" ... "/" ... "%" ... "||" ... "AND" ... "OR" ... "IS" ... "MEMBER" ... "SUBMULTISET" ... "CONTAINS" ... "OVERLAPS" ... "EQUALS" ... "PRECEDES" ... "SUCCEEDS" ... "IMMEDIATELY" ... "MULTISET" ... "[" ... "YEAR" ... "MONTH" ... "DAY" ... "HOUR" ... "MINUTE" ... "SECOND" ... 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.sql.parser.SqlParserTest$TesterImpl.parseStmtAndHandleEx(SqlParserTest.java:8199) ... 25 more Caused by: org.apache.calcite.sql.parser.impl.ParseException: Encountered "inner" at line 6, column 3. Was expecting one of: ")" ... "ORDER" ... "LIMIT" ... "OFFSET" ... "FETCH" ... "UNION" ... "INTERSECT" ... "EXCEPT" ... "MINUS" ... "NOT" ... "IN" ... "<" ... "<=" ... ">" ... ">=" ... "=" ... "<>" ... "!=" ... "BETWEEN" ... "LIKE" ... "SIMILAR" ... "+" ... "-" ... "*" ... "/" ... "%" ... "||" ... "AND" ... "OR" ... "IS" ... "MEMBER" ... "SUBMULTISET" ... "CONTAINS" ... "OVERLAPS" ... "EQUALS" ... "PRECEDES" ... "SUCCEEDS" ... "IMMEDIATELY" ... "MULTISET" ... "[" ... "YEAR" ... "MONTH" ... "DAY" ... "HOUR" ... "MINUTE" ... "SECOND" ... at org.apache.calcite.sql.parser.impl.SqlParserImpl.generateParseException(SqlParserImpl.java:22776) at org.apache.calcite.sql.parser.impl.SqlParserImpl.jj_consume_token(SqlParserImpl.java:22593) at org.apache.calcite.sql.parser.impl.SqlParserImpl.ParenthesizedExpression(SqlParserImpl.java:587) at org.apache.calcite.sql.parser.impl.SqlParserImpl.TableRef2(SqlParserImpl.java:1812) at org.apache.calcite.sql.parser.impl.SqlParserImpl.TableRef(SqlParserImpl.java:1756) at org.apache.calcite.sql.parser.impl.SqlParserImpl.FromClause(SqlParserImpl.java:1668) at org.apache.calcite.sql.parser.impl.SqlParserImpl.SqlSelect(SqlParserImpl.java:918) at org.apache.calcite.sql.parser.impl.SqlParserImpl.LeafQuery(SqlParserImpl.java:555) at org.apache.calcite.sql.parser.impl.SqlParserImpl.LeafQueryOrExpr(SqlParserImpl.java:3033) at org.apache.calcite.sql.parser.impl.SqlParserImpl.QueryOrExpr(SqlParserImpl.java:2952) at org.apache.calcite.sql.parser.impl.SqlParserImpl.OrderedQueryOrExpr(SqlParserImpl.java:466) at org.apache.calcite.sql.parser.impl.SqlParserImpl.SqlStmt(SqlParserImpl.java:844) at org.apache.calcite.sql.parser.impl.SqlParserImpl.SqlStmtEof(SqlParserImpl.java:872) at org.apache.calcite.sql.parser.impl.SqlParserImpl.parseSqlStmtEof(SqlParserImpl.java:187) at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:131) ... 27 more {code} was: I started working on a unit test in SqlParserTest (it's hard to predict exact output, so just have placeholder empty string for expectation right now). {code:java} @Test public void testInnerJoinOnSubqueryWithAggregation() { final String sql = "select *\n" + "from table1 \n" + "inner join (( \n" + " select * \n" + " from table2 ) \n" + " inner join ( \n" + " select * \n" + " from table3) \n" + " on table2.field1 = table3.field1) \n" + "on table1.field1 = table2.field1 \n"; sql(sql).ok(""); }{code} > SQL parser fails to parse valid multi nested join subqueries > ------------------------------------------------------------ > > Key: CALCITE-2153 > URL: https://issues.apache.org/jira/browse/CALCITE-2153 > Project: Calcite > Issue Type: Bug > Reporter: Samuel Waggoner > Assignee: Julian Hyde > Priority: Major > > I started working on a unit test in SqlParserTest (it's hard to predict exact > output, so I just have a placeholder empty string for expectation right now). > {code:java} > @Test public void testInnerJoinOnSubqueryWithAggregation() { > final String sql = "select *\n" > + "from table1 \n" > + "inner join (( \n" > + " select * \n" > + " from table2 ) \n" > + " inner join ( \n" > + " select * \n" > + " from table3) \n" > + " on table2.field1 = table3.field1) \n" > + "on table1.field1 = table2.field1 \n"; > sql(sql).ok(""); > }{code} > I believe this is valid SQL, but parsing fails with this exception > > {code:java} > java.lang.RuntimeException: Error while parsing SQL: select * > from table1 > inner join (( > select * > from table2 ) > inner join ( > select * > from table3) > on table2.field1 = table3.field1) > on table1.field1 = table2.field1 > at > org.apache.calcite.sql.parser.SqlParserTest$TesterImpl.parseStmtAndHandleEx(SqlParserTest.java:8201) > at > org.apache.calcite.sql.parser.SqlParserTest$TesterImpl.check(SqlParserTest.java:8186) > at > org.apache.calcite.sql.parser.SqlParserTest$Sql.ok(SqlParserTest.java:8384) > at > org.apache.calcite.sql.parser.SqlParserTest.testInnerJoinOnSubqueryWithAggregation(SqlParserTest.java:8156) > 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: Encountered > "inner" at line 6, column 3. > Was expecting one of: > ")" ... > "ORDER" ... > "LIMIT" ... > "OFFSET" ... > "FETCH" ... > "UNION" ... > "INTERSECT" ... > "EXCEPT" ... > "MINUS" ... > "NOT" ... > "IN" ... > "<" ... > "<=" ... > ">" ... > ">=" ... > "=" ... > "<>" ... > "!=" ... > "BETWEEN" ... > "LIKE" ... > "SIMILAR" ... > "+" ... > "-" ... > "*" ... > "/" ... > "%" ... > "||" ... > "AND" ... > "OR" ... > "IS" ... > "MEMBER" ... > "SUBMULTISET" ... > "CONTAINS" ... > "OVERLAPS" ... > "EQUALS" ... > "PRECEDES" ... > "SUCCEEDS" ... > "IMMEDIATELY" ... > "MULTISET" ... > "[" ... > "YEAR" ... > "MONTH" ... > "DAY" ... > "HOUR" ... > "MINUTE" ... > "SECOND" ... > > 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.sql.parser.SqlParserTest$TesterImpl.parseStmtAndHandleEx(SqlParserTest.java:8199) > ... 25 more > Caused by: org.apache.calcite.sql.parser.impl.ParseException: Encountered > "inner" at line 6, column 3. > Was expecting one of: > ")" ... > "ORDER" ... > "LIMIT" ... > "OFFSET" ... > "FETCH" ... > "UNION" ... > "INTERSECT" ... > "EXCEPT" ... > "MINUS" ... > "NOT" ... > "IN" ... > "<" ... > "<=" ... > ">" ... > ">=" ... > "=" ... > "<>" ... > "!=" ... > "BETWEEN" ... > "LIKE" ... > "SIMILAR" ... > "+" ... > "-" ... > "*" ... > "/" ... > "%" ... > "||" ... > "AND" ... > "OR" ... > "IS" ... > "MEMBER" ... > "SUBMULTISET" ... > "CONTAINS" ... > "OVERLAPS" ... > "EQUALS" ... > "PRECEDES" ... > "SUCCEEDS" ... > "IMMEDIATELY" ... > "MULTISET" ... > "[" ... > "YEAR" ... > "MONTH" ... > "DAY" ... > "HOUR" ... > "MINUTE" ... > "SECOND" ... > > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.generateParseException(SqlParserImpl.java:22776) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.jj_consume_token(SqlParserImpl.java:22593) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.ParenthesizedExpression(SqlParserImpl.java:587) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.TableRef2(SqlParserImpl.java:1812) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.TableRef(SqlParserImpl.java:1756) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.FromClause(SqlParserImpl.java:1668) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.SqlSelect(SqlParserImpl.java:918) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.LeafQuery(SqlParserImpl.java:555) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.LeafQueryOrExpr(SqlParserImpl.java:3033) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.QueryOrExpr(SqlParserImpl.java:2952) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.OrderedQueryOrExpr(SqlParserImpl.java:466) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.SqlStmt(SqlParserImpl.java:844) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.SqlStmtEof(SqlParserImpl.java:872) > at > org.apache.calcite.sql.parser.impl.SqlParserImpl.parseSqlStmtEof(SqlParserImpl.java:187) > at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:131) > ... 27 more > {code} > -- This message was sent by Atlassian JIRA (v7.6.3#76005)