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

Thomas Rebele edited comment on CALCITE-7294 at 11/20/25 1:26 PM:
------------------------------------------------------------------

Indeed, the bail-out logic handles the simplification. The following test 
passes with the 1.41 release:
{code:java}
checkSimplify(
        isNull(coalesce(plus(vInt(0), literal(0)) , vInt(1))),
        "IS NULL(COALESCE(?0.int0, ?0.int1))"); {code}
I think it would still make sense to not {{return null}} in simplifyIsNull and 
simplifyIsNotNull, as these methods already call {{{}simplify(a, UNKNOWN){}}}, 
so we would save to simplify the argument twice. What do you think, [~zabetak]?

Update: [my proposal|https://github.com/apache/calcite/pull/4646] to fix 
CALCITE-7296 would require that anyway.


was (Author: thomas.rebele):
Indeed, the bail-out logic handles the simplification. The following test 
passes with the 1.41 release:
{code:java}
checkSimplify(
        isNull(coalesce(plus(vInt(0), literal(0)) , vInt(1))),
        "IS NULL(COALESCE(?0.int0, ?0.int1))"); {code}
I think it would still make sense to not {{return null}} in simplifyIsNull and 
simplifyIsNotNull, as these methods already call {{{}simplify(a, UNKNOWN){}}}, 
so we would save to simplify the argument twice. What do you think, [~zabetak]?

> Simplify arguments to IS [NOT] NULL whenever possible
> -----------------------------------------------------
>
>                 Key: CALCITE-7294
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7294
>             Project: Calcite
>          Issue Type: Improvement
>          Components: core
>            Reporter: Stamatis Zampetakis
>            Priority: Major
>
> Currently there are few cases where {{RexSimplify}} bails out when attempting 
> to simplify an IS NULL/IS NOT NULL expression:
>  * 
> [https://github.com/apache/calcite/blob/31a23f38092c185ef0faf19f770c1de8625db0e8/core/src/main/java/org/apache/calcite/rex/RexSimplify.java#L1159]
>  * 
> [https://github.com/apache/calcite/blob/31a23f38092c185ef0faf19f770c1de8625db0e8/core/src/main/java/org/apache/calcite/rex/RexSimplify.java#L1190]
> It seems possible though to simplify the arguments and retain the IS NULL/IS 
> NOT NULL expression.
> {+}Example{+}:
> Currently {{COALESCE(age + 0, year) IS NULL}} cannot be simplified and is 
> returned as is. However, we could simplify the expression to {{COALESCE(age, 
> year) IS NULL}}.
> This improvement mainly affects IS NULL and IS NOT NULL simplification when 
> the argument is an function/operator with:
>  * [custom 
> nullability|https://github.com/apache/calcite/blob/31a23f38092c185ef0faf19f770c1de8625db0e8/core/src/main/java/org/apache/calcite/rex/RexSimplify.java#L1280]
>  (i.e., CAST, ITEM)
>  * {{Strong.Policy}} other than {{ANY}} and {{NOT_NULL}}



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

Reply via email to