[jira] [Updated] (CALCITE-2153) SQL parser fails to parse valid multi nested join subqueries

2018-01-29 Thread Samuel Waggoner (JIRA)

 [ 
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" ...
 "SEC

[jira] [Updated] (CALCITE-2153) SQL parser fails to parse valid multi nested join subqueries

2018-01-29 Thread Samuel Waggoner (JIRA)

 [ 
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 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}

  was:
{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 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}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Updated] (CALCITE-2153) SQL parser fails to parse valid multi nested join subqueries

2018-01-29 Thread Samuel Waggoner (JIRA)

 [ 
https://issues.apache.org/jira/browse/CALCITE-2153?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Samuel Waggoner updated CALCITE-2153:
-
Summary: SQL parser fails to parse valid multi nested join subqueries  
(was: SQL parser fails to parse valid triply nested join query)

> 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
>
> {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}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Created] (CALCITE-2153) SQL parser fails to parse valid triply nested join query

2018-01-29 Thread Samuel Waggoner (JIRA)
Samuel Waggoner created CALCITE-2153:


 Summary: SQL parser fails to parse valid triply nested join query
 Key: CALCITE-2153
 URL: https://issues.apache.org/jira/browse/CALCITE-2153
 Project: Calcite
  Issue Type: Bug
Reporter: Samuel Waggoner
Assignee: Julian Hyde


{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}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


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

2018-01-29 Thread Samuel Waggoner (JIRA)

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

Samuel Waggoner updated CALCITE-2152:
-
Summary: SQL parser unable to parse SQL with nested joins produced by 
RelToSqlConverter  (was: SQL parser unable to parse SQL produced by 
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
>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 
> 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

[jira] [Updated] (CALCITE-2152) SQL parser unable to parse SQL produced by RelToSqlConverter

2018-01-29 Thread Samuel Waggoner (JIRA)

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

Samuel Waggoner updated CALCITE-2152:
-
Description: 
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 org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:803)
 at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:788)
 at 
org.apache.calcite.sql.parser.impl.SqlParserImpl.checkNonQueryExpression(SqlParserImpl.java:294)
 at 
org.apache.calcite.sql.parser.impl.SqlParserImpl.Expression3(SqlParserImpl.java:3323)
 at 
org.apache.calcite.sql.parser.impl.SqlParserImpl.Expression2b(SqlParserImpl.java:3069)
 at 
org.apache.calcite.sql.parser.impl.SqlParserImpl.Expression2(SqlParserImpl.java:3095)
 at 
org.apache.calcite.sql.parser.impl.SqlParserImpl.Expression(SqlParserImpl.java:3048)
 at 
org.apache.calcite.sql.parser.impl.SqlParserImpl.LeafQueryOrExpr(SqlParserImpl

[jira] [Created] (CALCITE-2152) SQL parser unable to parse SQL produced by RelToSqlConverter

2018-01-29 Thread Samuel Waggoner (JIRA)
Samuel Waggoner created CALCITE-2152:


 Summary: SQL parser unable to parse SQL 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


I created this test case in RelToSqlConverterTest
```

@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();
}
```

result looks like this:
```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"```

Stack Trace is:
```

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 org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:803)
 at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:788)
 at 
org.apache.calcite.sql.parser.impl.SqlParserImpl.checkNonQueryExpression(SqlParserImpl.java:294)
 at 
org.apache.calcite.sql.parser.impl.SqlParserImpl.Expression3(SqlParserImpl.java:3323)
 at 
org.apache.calcite.sql.parser.impl.SqlParserImpl.Expression2b(SqlParserImpl.java:3069)
 at 
org.apache.calcite.sql.parser.impl.SqlParserImpl.Expression2(SqlParserImpl.java:3095)
 at 
org.apache.calcite.sql.parser.im

[jira] [Commented] (CALCITE-2143) RelToSqlConverter produces incorrect SQL with aggregation

2018-01-22 Thread Samuel Waggoner (JIRA)

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

Samuel Waggoner commented on CALCITE-2143:
--

PR here. As I note in the comments, I don't think this solution is very 
elegant, but wanted to get a maintainer's eyes on it. 

https://github.com/apache/calcite/pull/613

> RelToSqlConverter produces incorrect SQL with aggregation
> -
>
> Key: CALCITE-2143
> URL: https://issues.apache.org/jira/browse/CALCITE-2143
> Project: Calcite
>  Issue Type: Bug
>Affects Versions: 1.15.0
>Reporter: Austin Haas
>Assignee: Julian Hyde
>Priority: Major
>
> This plan:
> {code:java}
> LogicalAggregate(group=[{1}], my-alias=[SUM($0)])
>   LogicalAggregate(group=[{0, 1}])
> LogicalProject(b=[$2], a=[$0])
>   LogicalJoin(condition=[=($0, $1)], joinType=[inner])
> LogicalTableScan(table=[[rel-1]])
> LogicalTableScan(table=[[rel-2]]){code}
> Produces this erroneous SQL:
> {code:sql}
> SELECT `t0`.`my-alias` AS `a`, (SUM(`t0`.`a`)) AS `my-alias`
> FROM (SELECT `rel-2`.`b`, `rel-1`.`a`
>   FROM `rel-1`
>   INNER JOIN `rel-2` ON (`rel-1`.`a` = `rel-2`.`a`)
>   GROUP BY `rel-2`.`b`, `rel-1`.`a`) AS `t0`
> GROUP BY `t0`.`my-alias`{code}
> Note the first field of the outer SELECT, where 'my-alias' is aliased as 'a'.
> Any clues how to fix would be appreciated.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CALCITE-2143) RelToSqlConverter produces incorrect SQL with aggregation

2018-01-19 Thread Samuel Waggoner (JIRA)

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

Samuel Waggoner commented on CALCITE-2143:
--

I believe the problem is here:
[https://insight.io/github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java?line=949]

I'm working on a PR now.

> RelToSqlConverter produces incorrect SQL with aggregation
> -
>
> Key: CALCITE-2143
> URL: https://issues.apache.org/jira/browse/CALCITE-2143
> Project: Calcite
>  Issue Type: Bug
>Affects Versions: 1.15.0
>Reporter: Austin Haas
>Assignee: Julian Hyde
>Priority: Major
>
> This plan:
> {code:java}
> LogicalAggregate(group=[{1}], my-alias=[SUM($0)])
>   LogicalAggregate(group=[{0, 1}])
> LogicalProject(b=[$2], a=[$0])
>   LogicalJoin(condition=[=($0, $1)], joinType=[inner])
> LogicalTableScan(table=[[rel-1]])
> LogicalTableScan(table=[[rel-2]]){code}
> Produces this erroneous SQL:
> {code:sql}
> SELECT `t0`.`my-alias` AS `a`, (SUM(`t0`.`a`)) AS `my-alias`
> FROM (SELECT `rel-2`.`b`, `rel-1`.`a`
>   FROM `rel-1`
>   INNER JOIN `rel-2` ON (`rel-1`.`a` = `rel-2`.`a`)
>   GROUP BY `rel-2`.`b`, `rel-1`.`a`) AS `t0`
> GROUP BY `t0`.`my-alias`{code}
> Note the first field of the outer SELECT, where 'my-alias' is aliased as 'a'.
> Any clues how to fix would be appreciated.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)