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

mbudiu 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 6cbbf560b7 [CALCITE-7230] Compiler rejects comparisons between NULL 
and a ROW value
6cbbf560b7 is described below

commit 6cbbf560b721cb88354c33751aa72b16a58ded23
Author: Mihai Budiu <[email protected]>
AuthorDate: Wed Oct 15 14:30:25 2025 -0700

    [CALCITE-7230] Compiler rejects comparisons between NULL and a ROW value
    
    Signed-off-by: Mihai Budiu <[email protected]>
---
 core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java  | 8 ++++----
 core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java | 8 ++++++++
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java 
b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java
index 6a952aeaf3..42d6bc9edb 100644
--- a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java
+++ b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java
@@ -1655,10 +1655,6 @@ public static boolean isFlat(RelDataType type) {
    * @return Whether types are comparable
    */
   public static boolean isComparable(RelDataType type1, RelDataType type2) {
-    if (type1.isStruct() != type2.isStruct()) {
-      return false;
-    }
-
     final RelDataTypeFamily family1 = family(type1);
     final RelDataTypeFamily family2 = family(type2);
 
@@ -1668,6 +1664,10 @@ public static boolean isComparable(RelDataType type1, 
RelDataType type2) {
       return true;
     }
 
+    if (type1.isStruct() != type2.isStruct()) {
+      return false;
+    }
+
     if (type1.isStruct()) {
       int n = type1.getFieldCount();
       if (n != type2.getFieldCount()) {
diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java 
b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
index 7165d5d748..a4b1dc79ad 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -3494,6 +3494,14 @@ void testWinPartClause() {
     sql(query3).type(type);
   }
 
+  /** Test case for <a 
href="https://issues.apache.org/jira/browse/CALCITE-7230";>[CALCITE-7230]
+   * Compiler rejects comparisons between NULL and a ROW value</a>. */
+  @Test void coalesceRowNull() {
+    sql("SELECT COALESCE(NULL, ROW(1))")
+        .withValidatorConfig(c -> c.withCallRewrite(false))
+        .type("RecordType(RecordType(INTEGER EXPR$0) NOT NULL EXPR$0) NOT 
NULL");
+  }
+
   @Test void testAsOfJoin() {
     final String type0 = "RecordType(INTEGER NOT NULL EMPNO, INTEGER NOT NULL 
DEPTNO) NOT NULL";
     final String sql0 = "select emp.empno, dept.deptno from emp asof join 
dept\n"

Reply via email to