You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Mihai Budiu (Jira)" <ji...@apache.org> on 2025/10/16 15:13:00 UTC

[jira] [Commented] (CALCITE-7070) FILTER_REDUCE_EXPRESSIONS crashes on expression BETWEEN ( NULL) AND X

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

Mihai Budiu commented on CALCITE-7070:
--------------------------------------

Unfortunately I have to reopen this a second time; I will post here an example which triggers the bug.

My attempt to simplify the code has simplified the code too much.

The problem is the following: some data structures assume that there are no predicates that compare against null. The previous version of this code would check and remove such comparisons (which all evaluate to 'false'). In my last fix I only removed such comparisons from the input program. However, simplification steps can still produce such comparisons, so in the end an assertion fails:
{code:java}
Caused by: java.lang.AssertionError: Comparison with NULL in pulledUpPredicates    
    	at org.apache.calcite.util.Litmus.lambda$static$0(Litmus.java:31)
    	at org.apache.calcite.util.Litmus.check(Litmus.java:76)
    	at org.apache.calcite.plan.RelOptPredicateList.<init>(RelOptPredicateList.java:128)
    	at org.apache.calcite.plan.RelOptPredicateList.of(RelOptPredicateList.java:206)
    	at org.apache.calcite.rel.metadata.RelMdPredicates$JoinConditionBasedPredicateInference.inferPredicates(RelMdPredicates.java:839)
{code}

> FILTER_REDUCE_EXPRESSIONS crashes on expression BETWEEN ( NULL) AND X
> ---------------------------------------------------------------------
>
>                 Key: CALCITE-7070
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7070
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.40.0
>            Reporter: Mihai Budiu
>            Assignee: Mihai Budiu
>            Priority: Minor
>              Labels: pull-request-available
>             Fix For: 1.41.0
>
>
> The following test inserted in RelOptRulesTest crashes:
> {code}
>     final String sql = "SELECT + 54 FROM emp WHERE NOT CAST ( CAST(empno AS DOUBLE) AS INTEGER ) NOT BETWEEN ( NULL ) AND 89";
>     sql(sql)
>         .withRule(CoreRules.FILTER_REDUCE_EXPRESSIONS)
>         .check();
> {code}
> stack trace:
> {code}
> java.lang.AssertionError: value must not be null in null:INTEGER
> at org.apache.calcite.rex.RexSimplify.residue(RexSimplify.java:1968)
> 	at org.apache.calcite.rex.RexSimplify.simplifyUsingPredicates(RexSimplify.java:1909)
> 	at org.apache.calcite.rex.RexSimplify.simplifyComparison(RexSimplify.java:655)
> 	at org.apache.calcite.rex.RexSimplify.simplifyComparison(RexSimplify.java:517)
> 	at org.apache.calcite.rex.RexSimplify.simplify(RexSimplify.java:313)
> 	at org.apache.calcite.rex.RexSimplify.simplifyAndTerms(RexSimplify.java:694)
> 	at org.apache.calcite.rex.RexSimplify.simplifyAnd(RexSimplify.java:1559)
> 	at org.apache.calcite.rex.RexSimplify.simplify(RexSimplify.java:282)
> 	at org.apache.calcite.rex.RexSimplify.simplifyNot(RexSimplify.java:761)
> 	at org.apache.calcite.rex.RexSimplify.simplify(RexSimplify.java:286)
> 	at org.apache.calcite.rex.RexSimplify.simplifyUnknownAs(RexSimplify.java:251)
> 	at org.apache.calcite.rex.RexSimplify.simplifyPreservingType(RexSimplify.java:190)
> 	at org.apache.calcite.rel.rules.ReduceExpressionsRule.reduceExpressions(ReduceExpressionsRule.java:722)
> 	at org.apache.calcite.rel.rules.ReduceExpressionsRule$FilterReduceExpressionsRule.onMatch(ReduceExpressionsRule.java:159)
> {code}
> This test is modified from SqlLogicTest.



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