You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by "Chunwei Lei (Jira)" <ji...@apache.org> on 2020/03/06 07:29:00 UTC

[jira] [Created] (CALCITE-3845) CASE WHEN expression with nullability CAST is considered as reduced wrongly in ReduceExpressionsRule

Chunwei Lei created CALCITE-3845:
------------------------------------

             Summary: CASE WHEN expression with nullability CAST is considered as reduced wrongly in ReduceExpressionsRule
                 Key: CALCITE-3845
                 URL: https://issues.apache.org/jira/browse/CALCITE-3845
             Project: Calcite
          Issue Type: Bug
          Components: core
            Reporter: Chunwei Lei
            Assignee: Chunwei Lei


After ReduceExpressionsRule#reduceExpressionsInternal()[1],

 
{code:java}
CAST(CASE WHEN x then true WHEN y then TRUE ELSE false): boolean nullable (exp1) 
{code}
will be changed to 
{code:java}
WHEN x then CAST(true): boolean nullable WHEN y then CAST(true): boolean nullable ELSE CAST(false): boolean nullable.  (exp2){code}
Then exp1 is considered as reduced. In the next step, by ReduceExpressionsRule#simplifyPreservingType()[2], exp2 will be changed to 

 
{code:java}
CAST(CASE WHEN x then true WHEN y then TRUE ELSE false): boolean nullable (exp3)
{code}
, which is exactly the same as exp1.

Though exp1 is actually not reduced, it is still considered as reduced[3], which leads to CannotPlanException because of  setImportance(project, 0.0)[4].

 

[1][https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java#L618]

[2][https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java#L624]

 [3][https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java#L303]

 [4][https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java#L312]

 



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