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

Chunwei Lei resolved CALCITE-3845.
----------------------------------
    Fix Version/s: 1.23.0
       Resolution: Fixed

Fixed in 
[https://github.com/apache/calcite/commit/ad8cf7e0e96137c40103e0e83539b59e43513b17].

> 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
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.23.0
>
>          Time Spent: 1h 20m
>  Remaining Estimate: 0h
>
> 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)

Reply via email to