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

Mihai Budiu commented on CALCITE-7722:
--------------------------------------

Beware that multiplication can be applied to multiple data types, including 
intervals, and the semantics of overflow may depend on the data type. There's 
also a conformance setting about whether regular arithmetic is checked or not, 
and a pass which replaces MULTIPLY with CHECKED_MULTIPLY. But you have to make 
sure you don't simplify before this replacement occurs.

(github is down, so I quote from memory)

> Simplify IS NULL / IS NOT NULL expressions by removing operations if they do 
> not affect the nullability
> -------------------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-7722
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7722
>             Project: Calcite
>          Issue Type: Improvement
>            Reporter: Thomas Rebele
>            Assignee: Ruben Q L
>            Priority: Major
>              Labels: pull-request-available
>
> Example: consider the expression {{{}(CAST(col AS INT)*2) IS NULL{}}}. If the 
> operation uses integer overflows, then it does not affect the nullability. So 
> the expression can be simplified to {{{}CAST(col as INT) IS NULL{}}}.
> If the operation just returns NULL or throws an exception, then this 
> simplification would change the semantics. Calcite's built-in multiplication 
> [uses integer 
> overflows|https://github.com/apache/calcite/blob/437398834e49c8086a64870427214fec428684fc/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java#L844],
>  so it should carry out that simplification.
> However, currently the following RexProgramTest assertion fails:
> {code:java}
> checkSimplify(isNull(mul(vInt(), literal(2))), "IS NULL(?0.int0)"); {code}
> If the sub-expression may throw an exception, then the multiplication can 
> still be removed:
> {code:java}
> checkSimplify(isNull(mul(cast(vVarchar(), tInt(false)), literal(2))),
>         "IS NULL(CAST(?0.varchar0):INTEGER NOT NULL)"); {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to