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 cb4b5aefb2 [CALCITE-7653] ARRAY[NULL] produces uncompilable Java code
cb4b5aefb2 is described below

commit cb4b5aefb2a00d0792c273ad5f4ab4165f3ac81f
Author: Mihai Budiu <[email protected]>
AuthorDate: Mon Jul 13 17:37:11 2026 -0700

    [CALCITE-7653] ARRAY[NULL] produces uncompilable Java code
    
    Signed-off-by: Mihai Budiu <[email protected]>
---
 .../adapter/enumerable/RexToLixTranslator.java     |  9 ++++--
 core/src/test/resources/sql/cast.iq                | 32 ++++++++++++++++++++++
 2 files changed, 39 insertions(+), 2 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java
index ea4ff65127..5a1e0fee20 100644
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java
+++ 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java
@@ -401,10 +401,15 @@ private Expression getConvertExpression(
       final RelDataType targetDataType = targetType.getComponentType();
       assert sourceDataType != null;
       assert targetDataType != null;
+      final Type sourceComponentClass = 
typeFactory.getJavaClass(sourceDataType);
       final ParameterExpression parameter =
-          Expressions.parameter(typeFactory.getJavaClass(sourceDataType), 
"root");
+          Expressions.parameter(sourceComponentClass, "root");
+      // A NULL component type maps to java.lang.Void. Such elements are 
always null,
+      // so convert to a null constant instead of the parameter.
+      final Expression element =
+          sourceComponentClass == Void.class ? Expressions.constant(null) : 
parameter;
       Expression convert =
-          getConvertExpression(sourceDataType, targetDataType, parameter, 
format);
+          getConvertExpression(sourceDataType, targetDataType, element, 
format);
       return Expressions.call(BuiltInMethod.LIST_TRANSFORM.method, operand,
           Expressions.lambda(Function1.class, convert, parameter));
 
diff --git a/core/src/test/resources/sql/cast.iq 
b/core/src/test/resources/sql/cast.iq
index 9278af60c2..a0ef448854 100644
--- a/core/src/test/resources/sql/cast.iq
+++ b/core/src/test/resources/sql/cast.iq
@@ -1999,4 +1999,36 @@ select cast(mod(deptno, 3) as BOOLEAN), mod(deptno, 3) 
from emp;
 
 !ok
 
+# Test case for [CALCITE-7653] ARRAY[NULL] produces uncompilable Java code
+values (cast(array[null] as integer array));
++--------+
+| EXPR$0 |
++--------+
+| [null] |
++--------+
+(1 row)
+
+!ok
+
+select coalesce(cast(null as integer array), array[null]) as a
+from (values (1));
++--------+
+| A      |
++--------+
+| [null] |
++--------+
+(1 row)
+
+!ok
+
+values (cast(multiset[null] as integer multiset));
++--------+
+| EXPR$0 |
++--------+
+| [null] |
++--------+
+(1 row)
+
+!ok
+
 # End cast.iq

Reply via email to