Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-3845

CASE WHEN expression with nullability CAST is considered as reduced wrongly in ReduceExpressionsRule

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

      Description

      After ReduceExpressionsRule#reduceExpressionsInternal()[1],

      CAST(CASE WHEN x then true WHEN y then TRUE ELSE false): boolean nullable (exp1) 
      

      will be changed to 

      WHEN x then CAST(true): boolean nullable WHEN y then CAST(true): boolean nullable ELSE CAST(false): boolean nullable.  (exp2)

      Then exp1 is considered as reduced. In the next step, by ReduceExpressionsRule#simplifyPreservingType()[2], exp2 will be changed to 

      CAST(CASE WHEN x then true WHEN y then TRUE ELSE false): boolean nullable (exp3)
      

      , 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

       

        Attachments

          Activity

            People

            • Assignee:
              Chunwei Lei Chunwei Lei
              Reporter:
              Chunwei Lei Chunwei Lei

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 1h 20m
                1h 20m

                  Issue deployment