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 e3d5407d61 [CALCITE-7158] NULL cannot be cast to UUID
e3d5407d61 is described below

commit e3d5407d6118f7acc3c76e2ca03bfa7159feba16
Author: Mihai Budiu <[email protected]>
AuthorDate: Thu Sep 4 10:41:31 2025 -0700

    [CALCITE-7158] NULL cannot be cast to UUID
    
    Signed-off-by: Mihai Budiu <[email protected]>
---
 core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java  | 3 ++-
 core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java | 3 +++
 2 files changed, 5 insertions(+), 1 deletion(-)

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 add5190f2e..d302e4a63e 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
@@ -986,7 +986,8 @@ public static boolean canCastFrom(
       return true;
     }
     if (toType.getSqlTypeName() == SqlTypeName.UUID) {
-      return fromType.getSqlTypeName() == SqlTypeName.UUID
+      return fromType.getSqlTypeName() == SqlTypeName.NULL
+          || fromType.getSqlTypeName() == SqlTypeName.UUID
           || fromType.getFamily() == SqlTypeFamily.CHARACTER
           || fromType.getFamily() == SqlTypeFamily.BINARY;
     }
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 de7cd015ff..61c39e6416 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -851,6 +851,9 @@ static SqlOperatorTable operatorTableFor(SqlLibrary 
library) {
     expr("CAST(CAST('123e4567-e89b-12d3-a456-426655440000' AS VARCHAR) AS 
UUID)").ok();
     expr("CAST(x'123e4567e89b12d3a456426655440000' AS UUID)").ok();
     expr("CAST(CAST(x'123e4567e89b12d3a456426655440000' AS VARBINARY) AS 
UUID)").ok();
+    expr("CAST(NULL AS UUID)").ok();
+    // Test case for [CALCITE-7158] NULL cannot be cast to UUID
+    sql("SELECT UUID '123e4567-e89b-12d3-a456-426655440000' UNION SELECT 
NULL").ok();
   }
 
   @Test void testConcatWithCharset() {

Reply via email to