[jira] [Commented] (CALCITE-2444) Rel2Sql: support c IN (1,2)

2018-09-10 Thread Zoltan Haindrich (JIRA)


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

Zoltan Haindrich commented on CALCITE-2444:
---

[~julianhyde] Could you please take a look? I think I've addressed your noted 
issues - please let me know if there should be any more changes.

> Rel2Sql: support c IN (1,2)
> ---
>
> Key: CALCITE-2444
> URL: https://issues.apache.org/jira/browse/CALCITE-2444
> Project: Calcite
>  Issue Type: Bug
>  Components: jdbc-adapter
>Affects Versions: 1.17.0
>Reporter: Zoltan Haindrich
>Assignee: Zoltan Haindrich
>Priority: Major
>
> It is not possible to convert an Rel tree into an sql string if it contains a 
> filter which has an IN:
> example: `select * from emp where empno in (10,20)`
> note: Calcite's sql parser translates INs into either ORs or into a subquery.
> The following testcase can be added to RelToSqlConverterTest to reproduce the 
> issue:
> {code}
>   @Test public void testHiveIn() {
> // this can't be tested using "sql" because Calcite's sql parser replaces 
> INs with ORs or subqueries.
> final RelBuilder builder = 
> RelBuilder.create(RelBuilderTest.config().build());
> RexBuilder rexBuilder = builder.getRexBuilder();
> RelNode root =
> builder.scan("EMP")
> .filter(rexBuilder.makeCall(SqlStdOperatorTable.IN, 
> builder.field("DEPTNO"),
> builder.literal(20), builder.literal(21)))
> .build();
> RelNode rel = root;
> SqlDialect dialect = SqlDialect.DatabaseProduct.HIVE.getDialect();
> final RelToSqlConverter converter = new RelToSqlConverter(dialect);
> final SqlNode sqlNode = converter.visitChild(0, rel).asStatement();
> String sqlStr = sqlNode.toSqlString(dialect).getSql();
> assertEquals("select * from emp where deptno in (10,20)", sqlStr);
>   }
> {code}
> The exception is raised because calcite expects that every IN is a 
> subquery(because of sql2rel rewrites them)
> {code}
> Caused by: java.lang.reflect.InvocationTargetException
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_171]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524) 
> ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.dispatch(RelToSqlConverter.java:103)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visitChild(RelToSqlConverter.java:109)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:173)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_171]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524) 
> ~[calcite-core-1.17.0.jar:1.17.0]
> ... 61 more
> Caused by: java.lang.ClassCastException: org.apache.calcite.rex.RexCall 
> cannot be cast to org.apache.calcite.rex.RexSubQuery
> at 
> org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:540)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:166)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_171]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524) 
> ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.dispatch(RelToSqlConverter.java:103)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visitChild(RelToSqlConverter.java:109)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.re

[jira] [Commented] (CALCITE-2444) Rel2Sql: support c IN (1,2)

2018-08-30 Thread Zoltan Haindrich (JIRA)


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

Zoltan Haindrich commented on CALCITE-2444:
---

[~julianhyde] I've updated the pullrequest; I tried to address all of your 
comments. Let me know if there are any more issues with it.

> Rel2Sql: support c IN (1,2)
> ---
>
> Key: CALCITE-2444
> URL: https://issues.apache.org/jira/browse/CALCITE-2444
> Project: Calcite
>  Issue Type: Bug
>  Components: jdbc-adapter
>Affects Versions: 1.17.0
>Reporter: Zoltan Haindrich
>Assignee: Zoltan Haindrich
>Priority: Major
>
> It is not possible to convert an Rel tree into an sql string if it contains a 
> filter which has an IN:
> example: `select * from emp where empno in (10,20)`
> note: Calcite's sql parser translates INs into either ORs or into a subquery.
> The following testcase can be added to RelToSqlConverterTest to reproduce the 
> issue:
> {code}
>   @Test public void testHiveIn() {
> // this can't be tested using "sql" because Calcite's sql parser replaces 
> INs with ORs or subqueries.
> final RelBuilder builder = 
> RelBuilder.create(RelBuilderTest.config().build());
> RexBuilder rexBuilder = builder.getRexBuilder();
> RelNode root =
> builder.scan("EMP")
> .filter(rexBuilder.makeCall(SqlStdOperatorTable.IN, 
> builder.field("DEPTNO"),
> builder.literal(20), builder.literal(21)))
> .build();
> RelNode rel = root;
> SqlDialect dialect = SqlDialect.DatabaseProduct.HIVE.getDialect();
> final RelToSqlConverter converter = new RelToSqlConverter(dialect);
> final SqlNode sqlNode = converter.visitChild(0, rel).asStatement();
> String sqlStr = sqlNode.toSqlString(dialect).getSql();
> assertEquals("select * from emp where deptno in (10,20)", sqlStr);
>   }
> {code}
> The exception is raised because calcite expects that every IN is a 
> subquery(because of sql2rel rewrites them)
> {code}
> Caused by: java.lang.reflect.InvocationTargetException
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_171]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524) 
> ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.dispatch(RelToSqlConverter.java:103)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visitChild(RelToSqlConverter.java:109)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:173)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_171]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524) 
> ~[calcite-core-1.17.0.jar:1.17.0]
> ... 61 more
> Caused by: java.lang.ClassCastException: org.apache.calcite.rex.RexCall 
> cannot be cast to org.apache.calcite.rex.RexSubQuery
> at 
> org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:540)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:166)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_171]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524) 
> ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.dispatch(RelToSqlConverter.java:103)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visitChild(RelToSqlConverter.java:109)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sq

[jira] [Commented] (CALCITE-2444) Rel2Sql: support c IN (1,2)

2018-08-29 Thread Julian Hyde (JIRA)


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

Julian Hyde commented on CALCITE-2444:
--

Review comments:
* Use a better commit message. Users don't know what "Rel2Sql" is.
* In tests please use {{final String expected = ...; assertThat(sql, 
is(expected));}} rather than {{assertEquals}}. {{assertEquals}} has its 
arguments backwards, which confuses developers, so I try not to use it.
* Fix indentation. No space before close-paren.
* There's a lot of common code between tests to remove redundancy. Add a helper 
method. Maybe one argument to the helper method is a lambda that takes a 
RelBuilder and returns a RelNode.
* I don't think the tests need "Hive" in their name. They are testing IN. If 
you want one or two tests for Hive dialect that's fine, but they should be 
orthogonal.

> Rel2Sql: support c IN (1,2)
> ---
>
> Key: CALCITE-2444
> URL: https://issues.apache.org/jira/browse/CALCITE-2444
> Project: Calcite
>  Issue Type: Bug
>  Components: jdbc-adapter
>Affects Versions: 1.17.0
>Reporter: Zoltan Haindrich
>Assignee: Zoltan Haindrich
>Priority: Major
>
> It is not possible to convert an Rel tree into an sql string if it contains a 
> filter which has an IN:
> example: `select * from emp where empno in (10,20)`
> note: Calcite's sql parser translates INs into either ORs or into a subquery.
> The following testcase can be added to RelToSqlConverterTest to reproduce the 
> issue:
> {code}
>   @Test public void testHiveIn() {
> // this can't be tested using "sql" because Calcite's sql parser replaces 
> INs with ORs or subqueries.
> final RelBuilder builder = 
> RelBuilder.create(RelBuilderTest.config().build());
> RexBuilder rexBuilder = builder.getRexBuilder();
> RelNode root =
> builder.scan("EMP")
> .filter(rexBuilder.makeCall(SqlStdOperatorTable.IN, 
> builder.field("DEPTNO"),
> builder.literal(20), builder.literal(21)))
> .build();
> RelNode rel = root;
> SqlDialect dialect = SqlDialect.DatabaseProduct.HIVE.getDialect();
> final RelToSqlConverter converter = new RelToSqlConverter(dialect);
> final SqlNode sqlNode = converter.visitChild(0, rel).asStatement();
> String sqlStr = sqlNode.toSqlString(dialect).getSql();
> assertEquals("select * from emp where deptno in (10,20)", sqlStr);
>   }
> {code}
> The exception is raised because calcite expects that every IN is a 
> subquery(because of sql2rel rewrites them)
> {code}
> Caused by: java.lang.reflect.InvocationTargetException
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_171]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524) 
> ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.dispatch(RelToSqlConverter.java:103)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visitChild(RelToSqlConverter.java:109)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:173)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_171]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524) 
> ~[calcite-core-1.17.0.jar:1.17.0]
> ... 61 more
> Caused by: java.lang.ClassCastException: org.apache.calcite.rex.RexCall 
> cannot be cast to org.apache.calcite.rex.RexSubQuery
> at 
> org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:540)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:166)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcc

[jira] [Commented] (CALCITE-2444) Rel2Sql: support c IN (1,2)

2018-08-29 Thread Zoltan Haindrich (JIRA)


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

Zoltan Haindrich commented on CALCITE-2444:
---

I have added one more - but I feel that these tests are not really increase the 
coverage in SqlImplementor.

> Rel2Sql: support c IN (1,2)
> ---
>
> Key: CALCITE-2444
> URL: https://issues.apache.org/jira/browse/CALCITE-2444
> Project: Calcite
>  Issue Type: Bug
>  Components: jdbc-adapter
>Affects Versions: 1.17.0
>Reporter: Zoltan Haindrich
>Assignee: Zoltan Haindrich
>Priority: Major
>
> It is not possible to convert an Rel tree into an sql string if it contains a 
> filter which has an IN:
> example: `select * from emp where empno in (10,20)`
> note: Calcite's sql parser translates INs into either ORs or into a subquery.
> The following testcase can be added to RelToSqlConverterTest to reproduce the 
> issue:
> {code}
>   @Test public void testHiveIn() {
> // this can't be tested using "sql" because Calcite's sql parser replaces 
> INs with ORs or subqueries.
> final RelBuilder builder = 
> RelBuilder.create(RelBuilderTest.config().build());
> RexBuilder rexBuilder = builder.getRexBuilder();
> RelNode root =
> builder.scan("EMP")
> .filter(rexBuilder.makeCall(SqlStdOperatorTable.IN, 
> builder.field("DEPTNO"),
> builder.literal(20), builder.literal(21)))
> .build();
> RelNode rel = root;
> SqlDialect dialect = SqlDialect.DatabaseProduct.HIVE.getDialect();
> final RelToSqlConverter converter = new RelToSqlConverter(dialect);
> final SqlNode sqlNode = converter.visitChild(0, rel).asStatement();
> String sqlStr = sqlNode.toSqlString(dialect).getSql();
> assertEquals("select * from emp where deptno in (10,20)", sqlStr);
>   }
> {code}
> The exception is raised because calcite expects that every IN is a 
> subquery(because of sql2rel rewrites them)
> {code}
> Caused by: java.lang.reflect.InvocationTargetException
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_171]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524) 
> ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.dispatch(RelToSqlConverter.java:103)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visitChild(RelToSqlConverter.java:109)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:173)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_171]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524) 
> ~[calcite-core-1.17.0.jar:1.17.0]
> ... 61 more
> Caused by: java.lang.ClassCastException: org.apache.calcite.rex.RexCall 
> cannot be cast to org.apache.calcite.rex.RexSubQuery
> at 
> org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:540)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:166)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_171]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524) 
> ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.dispatch(RelToSqlConverter.java:103)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visitChild(RelToSqlConverter.java:109)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(R

[jira] [Commented] (CALCITE-2444) Rel2Sql: support c IN (1,2)

2018-08-29 Thread Vladimir Sitnikov (JIRA)


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

Vladimir Sitnikov commented on CALCITE-2444:


[~kgyrtkirk], I meant to add test caseS. Two of them: one for a in (1), the 
other for row(a,b) in (row(c,d)) or something like that

> Rel2Sql: support c IN (1,2)
> ---
>
> Key: CALCITE-2444
> URL: https://issues.apache.org/jira/browse/CALCITE-2444
> Project: Calcite
>  Issue Type: Bug
>  Components: jdbc-adapter
>Affects Versions: 1.17.0
>Reporter: Zoltan Haindrich
>Assignee: Zoltan Haindrich
>Priority: Major
>
> It is not possible to convert an Rel tree into an sql string if it contains a 
> filter which has an IN:
> example: `select * from emp where empno in (10,20)`
> note: Calcite's sql parser translates INs into either ORs or into a subquery.
> The following testcase can be added to RelToSqlConverterTest to reproduce the 
> issue:
> {code}
>   @Test public void testHiveIn() {
> // this can't be tested using "sql" because Calcite's sql parser replaces 
> INs with ORs or subqueries.
> final RelBuilder builder = 
> RelBuilder.create(RelBuilderTest.config().build());
> RexBuilder rexBuilder = builder.getRexBuilder();
> RelNode root =
> builder.scan("EMP")
> .filter(rexBuilder.makeCall(SqlStdOperatorTable.IN, 
> builder.field("DEPTNO"),
> builder.literal(20), builder.literal(21)))
> .build();
> RelNode rel = root;
> SqlDialect dialect = SqlDialect.DatabaseProduct.HIVE.getDialect();
> final RelToSqlConverter converter = new RelToSqlConverter(dialect);
> final SqlNode sqlNode = converter.visitChild(0, rel).asStatement();
> String sqlStr = sqlNode.toSqlString(dialect).getSql();
> assertEquals("select * from emp where deptno in (10,20)", sqlStr);
>   }
> {code}
> The exception is raised because calcite expects that every IN is a 
> subquery(because of sql2rel rewrites them)
> {code}
> Caused by: java.lang.reflect.InvocationTargetException
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_171]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524) 
> ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.dispatch(RelToSqlConverter.java:103)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visitChild(RelToSqlConverter.java:109)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:173)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_171]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524) 
> ~[calcite-core-1.17.0.jar:1.17.0]
> ... 61 more
> Caused by: java.lang.ClassCastException: org.apache.calcite.rex.RexCall 
> cannot be cast to org.apache.calcite.rex.RexSubQuery
> at 
> org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:540)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:166)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_171]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524) 
> ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.dispatch(RelToSqlConverter.java:103)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visitChild(RelToSqlConverter.java:109)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql

[jira] [Commented] (CALCITE-2444) Rel2Sql: support c IN (1,2)

2018-08-29 Thread Zoltan Haindrich (JIRA)


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

Zoltan Haindrich commented on CALCITE-2444:
---

[~vladimirsitnikov] I've added a test for that as well.

> Rel2Sql: support c IN (1,2)
> ---
>
> Key: CALCITE-2444
> URL: https://issues.apache.org/jira/browse/CALCITE-2444
> Project: Calcite
>  Issue Type: Bug
>  Components: jdbc-adapter
>Affects Versions: 1.17.0
>Reporter: Zoltan Haindrich
>Assignee: Zoltan Haindrich
>Priority: Major
>
> It is not possible to convert an Rel tree into an sql string if it contains a 
> filter which has an IN:
> example: `select * from emp where empno in (10,20)`
> note: Calcite's sql parser translates INs into either ORs or into a subquery.
> The following testcase can be added to RelToSqlConverterTest to reproduce the 
> issue:
> {code}
>   @Test public void testHiveIn() {
> // this can't be tested using "sql" because Calcite's sql parser replaces 
> INs with ORs or subqueries.
> final RelBuilder builder = 
> RelBuilder.create(RelBuilderTest.config().build());
> RexBuilder rexBuilder = builder.getRexBuilder();
> RelNode root =
> builder.scan("EMP")
> .filter(rexBuilder.makeCall(SqlStdOperatorTable.IN, 
> builder.field("DEPTNO"),
> builder.literal(20), builder.literal(21)))
> .build();
> RelNode rel = root;
> SqlDialect dialect = SqlDialect.DatabaseProduct.HIVE.getDialect();
> final RelToSqlConverter converter = new RelToSqlConverter(dialect);
> final SqlNode sqlNode = converter.visitChild(0, rel).asStatement();
> String sqlStr = sqlNode.toSqlString(dialect).getSql();
> assertEquals("select * from emp where deptno in (10,20)", sqlStr);
>   }
> {code}
> The exception is raised because calcite expects that every IN is a 
> subquery(because of sql2rel rewrites them)
> {code}
> Caused by: java.lang.reflect.InvocationTargetException
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_171]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524) 
> ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.dispatch(RelToSqlConverter.java:103)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visitChild(RelToSqlConverter.java:109)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:173)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_171]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524) 
> ~[calcite-core-1.17.0.jar:1.17.0]
> ... 61 more
> Caused by: java.lang.ClassCastException: org.apache.calcite.rex.RexCall 
> cannot be cast to org.apache.calcite.rex.RexSubQuery
> at 
> org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:540)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:166)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_171]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524) 
> ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.dispatch(RelToSqlConverter.java:103)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visitChild(RelToSqlConverter.java:109)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:173)
>  ~[calcite-core-1.17.0.j

[jira] [Commented] (CALCITE-2444) Rel2Sql: support c IN (1,2)

2018-08-29 Thread Vladimir Sitnikov (JIRA)


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

Vladimir Sitnikov commented on CALCITE-2444:


[~kgyrtkirk], please add test cases for ONE element in the IN braces as well.

> Rel2Sql: support c IN (1,2)
> ---
>
> Key: CALCITE-2444
> URL: https://issues.apache.org/jira/browse/CALCITE-2444
> Project: Calcite
>  Issue Type: Bug
>  Components: jdbc-adapter
>Affects Versions: 1.17.0
>Reporter: Zoltan Haindrich
>Assignee: Zoltan Haindrich
>Priority: Major
>
> It is not possible to convert an Rel tree into an sql string if it contains a 
> filter which has an IN:
> example: `select * from emp where empno in (10,20)`
> note: Calcite's sql parser translates INs into either ORs or into a subquery.
> The following testcase can be added to RelToSqlConverterTest to reproduce the 
> issue:
> {code}
>   @Test public void testHiveIn() {
> // this can't be tested using "sql" because Calcite's sql parser replaces 
> INs with ORs or subqueries.
> final RelBuilder builder = 
> RelBuilder.create(RelBuilderTest.config().build());
> RexBuilder rexBuilder = builder.getRexBuilder();
> RelNode root =
> builder.scan("EMP")
> .filter(rexBuilder.makeCall(SqlStdOperatorTable.IN, 
> builder.field("DEPTNO"),
> builder.literal(20), builder.literal(21)))
> .build();
> RelNode rel = root;
> SqlDialect dialect = SqlDialect.DatabaseProduct.HIVE.getDialect();
> final RelToSqlConverter converter = new RelToSqlConverter(dialect);
> final SqlNode sqlNode = converter.visitChild(0, rel).asStatement();
> String sqlStr = sqlNode.toSqlString(dialect).getSql();
> assertEquals("select * from emp where deptno in (10,20)", sqlStr);
>   }
> {code}
> The exception is raised because calcite expects that every IN is a 
> subquery(because of sql2rel rewrites them)
> {code}
> Caused by: java.lang.reflect.InvocationTargetException
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_171]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524) 
> ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.dispatch(RelToSqlConverter.java:103)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visitChild(RelToSqlConverter.java:109)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:173)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_171]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524) 
> ~[calcite-core-1.17.0.jar:1.17.0]
> ... 61 more
> Caused by: java.lang.ClassCastException: org.apache.calcite.rex.RexCall 
> cannot be cast to org.apache.calcite.rex.RexSubQuery
> at 
> org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:540)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:166)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_171]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524) 
> ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.dispatch(RelToSqlConverter.java:103)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visitChild(RelToSqlConverter.java:109)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:173)
> 

[jira] [Commented] (CALCITE-2444) Rel2Sql: support c IN (1,2)

2018-08-28 Thread Zoltan Haindrich (JIRA)


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

Zoltan Haindrich commented on CALCITE-2444:
---

opened pullrequest: https://github.com/apache/calcite/pull/805

> Rel2Sql: support c IN (1,2)
> ---
>
> Key: CALCITE-2444
> URL: https://issues.apache.org/jira/browse/CALCITE-2444
> Project: Calcite
>  Issue Type: Bug
>  Components: jdbc-adapter
>Affects Versions: 1.17.0
>Reporter: Zoltan Haindrich
>Assignee: Zoltan Haindrich
>Priority: Major
>
> It is not possible to convert an Rel tree into an sql string if it contains a 
> filter which has an IN:
> example: `select * from emp where empno in (10,20)`
> note: Calcite's sql parser translates INs into either ORs or into a subquery.
> The following testcase can be added to RelToSqlConverterTest to reproduce the 
> issue:
> {code}
>   @Test public void testHiveIn() {
> // this can't be tested using "sql" because Calcite's sql parser replaces 
> INs with ORs or subqueries.
> final RelBuilder builder = 
> RelBuilder.create(RelBuilderTest.config().build());
> RexBuilder rexBuilder = builder.getRexBuilder();
> RelNode root =
> builder.scan("EMP")
> .filter(rexBuilder.makeCall(SqlStdOperatorTable.IN, 
> builder.field("DEPTNO"),
> builder.literal(20), builder.literal(21)))
> .build();
> RelNode rel = root;
> SqlDialect dialect = SqlDialect.DatabaseProduct.HIVE.getDialect();
> final RelToSqlConverter converter = new RelToSqlConverter(dialect);
> final SqlNode sqlNode = converter.visitChild(0, rel).asStatement();
> String sqlStr = sqlNode.toSqlString(dialect).getSql();
> assertEquals("select * from emp where deptno in (10,20)", sqlStr);
>   }
> {code}
> The exception is raised because calcite expects that every IN is a 
> subquery(because of sql2rel rewrites them)
> {code}
> Caused by: java.lang.reflect.InvocationTargetException
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_171]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524) 
> ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.dispatch(RelToSqlConverter.java:103)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visitChild(RelToSqlConverter.java:109)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:173)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_171]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524) 
> ~[calcite-core-1.17.0.jar:1.17.0]
> ... 61 more
> Caused by: java.lang.ClassCastException: org.apache.calcite.rex.RexCall 
> cannot be cast to org.apache.calcite.rex.RexSubQuery
> at 
> org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:540)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:166)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_171]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524) 
> ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.dispatch(RelToSqlConverter.java:103)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visitChild(RelToSqlConverter.java:109)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:173)
>  ~[calcite-core-1

[jira] [Commented] (CALCITE-2444) Rel2Sql: support c IN (1,2)

2018-08-28 Thread Zoltan Haindrich (JIRA)


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

Zoltan Haindrich commented on CALCITE-2444:
---

I've went into a little bit of overcomplicating it first; but eventually I've 
found a simple solution

My original approach was to add a custom unparse to SqlInOperator; but it 
interfered with the existing subquery and IN handling logics
I don't feel it right that even thru as a RexNode the IN has variable number of 
children; from which the first is the left hand side of the in.
In the meantime the SqlNode has always 2 arguments; the first is a "list" of 
arguments and the second is the "left hand side"...

> Rel2Sql: support c IN (1,2)
> ---
>
> Key: CALCITE-2444
> URL: https://issues.apache.org/jira/browse/CALCITE-2444
> Project: Calcite
>  Issue Type: Bug
>  Components: jdbc-adapter
>Affects Versions: 1.17.0
>Reporter: Zoltan Haindrich
>Assignee: Zoltan Haindrich
>Priority: Major
>
> It is not possible to convert an Rel tree into an sql string if it contains a 
> filter which has an IN:
> example: `select * from emp where empno in (10,20)`
> note: Calcite's sql parser translates INs into either ORs or into a subquery.
> The following testcase can be added to RelToSqlConverterTest to reproduce the 
> issue:
> {code}
>   @Test public void testHiveIn() {
> // this can't be tested using "sql" because Calcite's sql parser replaces 
> INs with ORs or subqueries.
> final RelBuilder builder = 
> RelBuilder.create(RelBuilderTest.config().build());
> RexBuilder rexBuilder = builder.getRexBuilder();
> RelNode root =
> builder.scan("EMP")
> .filter(rexBuilder.makeCall(SqlStdOperatorTable.IN, 
> builder.field("DEPTNO"),
> builder.literal(20), builder.literal(21)))
> .build();
> RelNode rel = root;
> SqlDialect dialect = SqlDialect.DatabaseProduct.HIVE.getDialect();
> final RelToSqlConverter converter = new RelToSqlConverter(dialect);
> final SqlNode sqlNode = converter.visitChild(0, rel).asStatement();
> String sqlStr = sqlNode.toSqlString(dialect).getSql();
> assertEquals("select * from emp where deptno in (10,20)", sqlStr);
>   }
> {code}
> The exception is raised because calcite expects that every IN is a 
> subquery(because of sql2rel rewrites them)
> {code}
> Caused by: java.lang.reflect.InvocationTargetException
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_171]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524) 
> ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.dispatch(RelToSqlConverter.java:103)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visitChild(RelToSqlConverter.java:109)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:173)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_171]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524) 
> ~[calcite-core-1.17.0.jar:1.17.0]
> ... 61 more
> Caused by: java.lang.ClassCastException: org.apache.calcite.rex.RexCall 
> cannot be cast to org.apache.calcite.rex.RexSubQuery
> at 
> org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:540)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at 
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:166)
>  ~[calcite-core-1.17.0.jar:1.17.0]
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_171]
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_171]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
> at org.apache.calcite.util.ReflectUtil$2.invo