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

Vladimir Sitnikov commented on CALCITE-2450:
--------------------------------------------

{{pushPredicateIntoCase}} seems to push case into functions like
{noformat}
    // Convert
    //   f(CASE WHEN p1 THEN v1 ... END, arg)
    // to
    //   CASE WHEN p1 THEN f(v1, arg) ... END
{noformat}
 
https://github.com/apache/calcite/blob/c3b160d8f770e61741cbe1b610846af3e08e9ffe/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java#L716-L729

Well, there's exception for AND/OR/CASE, however I'm sure such transformation 
would violate {{x > 0 and y / x < 6}}.

For instance:
{{my_function(case when x>0 then 1 end, oh_dear/0)}}  would hide "division by 
zero" when converted to {{case when x>0 then my_function(1, oh_dear/0)}}


> RexSimplify: reorder predicates to a canonical form as a part of RexSimplify
> ----------------------------------------------------------------------------
>
>                 Key: CALCITE-2450
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2450
>             Project: Calcite
>          Issue Type: Sub-task
>          Components: core
>    Affects Versions: 1.17.0
>            Reporter: Vladimir Sitnikov
>            Assignee: Julian Hyde
>            Priority: Major
>
> Certain optimizations are easier to perform when input expressions are in a 
> canonical form.
> For instance: more duplicates can be found in AND/OR lists, case branches, 
> etc.
> Note: this reordering is supposed to happen in RexSimplify only. In other 
> words, RexBuilder would still produce "non-canonical" expressions.
> It is expected that {{RexSimplify}} might alter the expression, so if it 
> converts {{5=x}} to {{x=5}} it should be just fine.
> The suggested rules are to be discussed, yet the following might be fine:
> 1) For AND, OR, IN: put "simpler" nodes first. The weight of a node could be 
> either {{.toString().length()}} or a number of child nodes or something like 
> that.
> The motivation is to simplify logic that handles "duplicate" entries. It 
> won't have to consider "both alternatives" all over the place.
> 2) For comparison with literals put literal as the second argument
> 3) For binary comparison, put node with less weight to the left



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to