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

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

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

Chunwei Lei edited comment on CALCITE-3845 at 3/6/20, 7:35 AM:
---------------------------------------------------------------

IMO, there are 3 ways to fix this issue:

1) do not push nullability CAST to CASE

2) do not simplify {{cast(true): boolean nullable}} to true

3) do not consider as reduced if the case happens

Personally I prefer 3.


was (Author: chunwei lei):
IMO, there are 3 ways to fix this issue:

1) do not push nullability CAST to CASE

2) do not simplify cast(true): boolean nullable to true

3) do not consider as reduced if the case happens

Personally I prefer 3.

> 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
>          Time Spent: 10m
>  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)