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

Steven Talbot commented on CALCITE-4620:
----------------------------------------

Yep, I can repro, here's a test that blows up:

 

 
{code:java}
@Test void testCaseGeneratingJoinCondition() {
  final String sql = "SELECT v1.deptno, v2.deptno\n"
      + "FROM dept v1 LEFT JOIN emp v2 ON CASE WHEN v2.job = 'PRESIDENT' THEN 
true ELSE v1.deptno = 10 END\n"
      + "WHERE v2.job LIKE 'PRESIDENT'";
  final String expected = "SELECT \"DEPT\".\"DEPTNO\","
      + " \"EMP\".\"DEPTNO\" AS \"DEPTNO0\"\n"
      + "FROM \"SCOTT\".\"DEPT\"\n"
      + "LEFT JOIN \"SCOTT\".\"EMP\""
      + " ON \"DEPT\".\"DEPTNO\" = \"EMP\".\"DEPTNO\"\n" // this would of 
course change
      + "WHERE \"EMP\".\"JOB\" LIKE 'PRESIDENT'";
  sql(sql)
      .schema(CalciteAssert.SchemaSpec.JDBC_SCOTT)
      .ok(expected);
}
{code}
 

Stack trace from master (fd6ffc90)
{noformat}
CASE(=($5, 'PRESIDENT'), true, =(CAST($0):INTEGER NOT NULL, 10))
java.lang.AssertionError: CASE(=($5, 'PRESIDENT'), true, =(CAST($0):INTEGER NOT 
NULL, 10))
  at 
org.apache.calcite.rel.rel2sql.SqlImplementor.convertConditionToSqlNode(SqlImplementor.java:381)
  at 
org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:222)
  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.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:531)
  at 
org.apache.calcite.rel.rel2sql.RelToSqlConverter.dispatch(RelToSqlConverter.java:134)
  at 
org.apache.calcite.rel.rel2sql.RelToSqlConverter.visitInput(RelToSqlConverter.java:142)
  at 
org.apache.calcite.rel.rel2sql.SqlImplementor.visitInput(SqlImplementor.java:185){noformat}
What's interesting, and gave me pause, is that in the debugger I saw a similar 
condition convert to an `IS_NOT_TRUE` instead of a CASE... but of course that 
_also_ blows up in the RelToSqlConverter at that point.

 

It doesn't look like IS_TRUE/IS_NOT_TRUE/IS_FALSE/IS_NOT_FALSE are implemented 
in that method either.

> join on non-reducible CASE causes AssertionError in RelToSqlConverter
> ---------------------------------------------------------------------
>
>                 Key: CALCITE-4620
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4620
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Steven Talbot
>            Priority: Major
>
> Basically  CALCITE-4610  but this time with a CASE WHEN. 
> I can provide a repro test if needed, but any join with a condition like in 
> that same test
> {code:java}
> CASE WHEN a = 'some_literal' THEN true ELSE c = 'some_other_literal' END{code}
> The CASE travels through the pipeline, and the RelToSqlConverter crashes on 
> it in convertConditionToSqlNode.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to