This is an automated email from the ASF dual-hosted git repository.

mihaibudiu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
     new 19a2c21783 [CALCITE-7598] Query with HAVING empno BETWEEN NULL AND 
NULL crashes the compiler
19a2c21783 is described below

commit 19a2c2178368fb108530e2fe7dcc46e58dc5cadc
Author: Mihai Budiu <[email protected]>
AuthorDate: Wed Jun 10 11:38:27 2026 -0700

    [CALCITE-7598] Query with HAVING empno BETWEEN NULL AND NULL crashes the 
compiler
    
    Signed-off-by: Mihai Budiu <[email protected]>
---
 .../java/org/apache/calcite/sql2rel/SqlToRelConverter.java     |  3 ++-
 .../src/test/java/org/apache/calcite/test/RelMetadataTest.java | 10 ++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git 
a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java 
b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
index 9c328b152f..4d14e16937 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
@@ -3819,7 +3819,8 @@ private void createAggImpl(Blackboard bb,
       if (having != null) {
         SqlNode newHaving = pushDownNotForIn(bb.scope, having);
         replaceSubQueries(bb, newHaving, RelOptUtil.Logic.UNKNOWN_AS_FALSE);
-        havingExpr = bb.convertExpression(newHaving);
+        RexNode having0 = bb.convertExpression(newHaving);
+        havingExpr = simplifyPredicate(having0);
       } else {
         havingExpr = relBuilder.literal(true);
       }
diff --git a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java 
b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
index f438a0ad94..9c3c30e344 100644
--- a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
@@ -4531,6 +4531,16 @@ private void assertExpressionLineage(
     SqlValidatorTester.DEFAULT.convertSqlToRel(factory, sql, false, false);
   }
 
+  /** Test case for <a 
href="https://issues.apache.org/jira/browse/CALCITE-7598";>[CALCITE-7598]
+   * Query with HAVING empno BETWEEN NULL AND NULL crashes the compiler</a>. */
+  @Test void testHavingCrash() {
+    String sql = "SELECT DISTINCT empno FROM emp GROUP BY empno HAVING empno 
BETWEEN NULL AND NULL";
+    SqlTestFactory factory = SqlTestFactory.INSTANCE
+        .withSqlToRelConfig(
+            c -> c.withRelBuilderConfigTransform(t -> t.withSimplify(false)));
+    SqlValidatorTester.DEFAULT.convertSqlToRel(factory, sql, false, false);
+  }
+
   @Test void testAllPredicates() {
     final Project rel = (Project) sql("select * from emp, dept").toRel();
     final Join join = (Join) rel.getInput();

Reply via email to