My changes to convert boolean CASE into AND/OR expression are causing a failure 
in CalciteSqlOperatorTest.testIsDistinctFromOperator for the expression
cast(null as integer) is distinct from 2

I can see that the CASE logic is being triggered and the conversion occurs:

CASE($t2, $t4, $t5, $t6, $t7)
is converted into:
OR(AND($t2, $t4), AND(NOT($t2), $t5, $t6), AND(NOT($t2), NOT($t5), $t7))

This is the test failure:

testIsNotDistinctFromOperator(org.apache.calcite.test.CalciteSqlOperatorTest)  
Time elapsed: 1.991 sec  <<< ERROR!
java.lang.RuntimeException: java.sql.SQLException: Error while executing SQL 
"values (cast(null as integer) is not distinct from 2)": null
Caused by: java.sql.SQLException: Error while executing SQL "values (cast(null 
as integer) is not distinct from 2)": null
Caused by: org.apache.calcite.adapter.enumerable.RexToLixTranslator$AlwaysNull

The call being translated is this:
<>($t1, CAST($t9):INTEGER)

I see that RelOptUtil.isDistinctFromInternal transforms the  x IS DISTINCT FROM 
y call into

CASE
  WHEN IS_NULL(x) THEN IS_NOT_NULL(y)
  WHEN IS_NULL(y) THEN IS_NOT_NULL(x)
  ELSE x <> y
END

My new simplifyCase changes this into:
  (IS_NULL(X) AND IS_NOT_NULL(y)) OR (NOT IS_NULL(x) AND IS_NULL(y) AND 
IS_NOT_NULL(x)) OR (NOT IS_NULL(X) AND NOT IS_NULL(y) AND x <> y)

So, if I understand correctly, w/o my change the RexToLix translation would 
never have to visit the else branch and deal with the null<>2 case? I did a 
brief search, but I did not find anything specific to CASE in 
RexToLixTranslator.

Thanks,
~Remus



Reply via email to