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 355ed1b10b [CALCITE-7721] CAST of a ROW ARRAY element raises
NullPointerException
355ed1b10b is described below
commit 355ed1b10b634c56931f9f84987574688df8bae3
Author: Mihai Budiu <[email protected]>
AuthorDate: Fri Aug 14 10:50:33 2026 -0700
[CALCITE-7721] CAST of a ROW ARRAY element raises NullPointerException
Signed-off-by: Mihai Budiu <[email protected]>
---
.../adapter/enumerable/RexToLixTranslator.java | 6 ++++
core/src/test/resources/sql/struct.iq | 35 ++++++++++++++++++++++
2 files changed, 41 insertions(+)
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 f102fd69d7..35373aca3e 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
@@ -361,6 +361,12 @@ private Expression getRowConvertExpression(
return Expressions.constant(null);
}
assert sourceType.getSqlTypeName() == SqlTypeName.ROW;
+ if (Types.getComponentType(operand.getType()) == null) {
+ // A ROW value is represented as an Object[] at runtime, but the
+ // expression that produces it may have type Object, for example an
+ // element of an array; the field access below requires an array.
+ operand = Expressions.convert_(operand, Object[].class);
+ }
List<RelDataTypeField> targetTypes = targetType.getFieldList();
List<RelDataTypeField> sourceTypes = sourceType.getFieldList();
assert targetTypes.size() == sourceTypes.size();
diff --git a/core/src/test/resources/sql/struct.iq
b/core/src/test/resources/sql/struct.iq
index 08c8762050..4356030dc5 100644
--- a/core/src/test/resources/sql/struct.iq
+++ b/core/src/test/resources/sql/struct.iq
@@ -420,4 +420,39 @@ from (values (1)) as t2(x), (select ARRAY[ROW(ROW(1, 2),
3)] as arr) as t;
!ok
+# [CALCITE-7721] CAST of a ROW ARRAY element raises NullPointerException.
+select cast(t.arr[1] as row(x integer, y integer)) as v
+from (select ARRAY[ROW(1, 2)] as arr) as t;
++--------+
+| V |
++--------+
+| {1, 2} |
++--------+
+(1 row)
+
+!ok
+
+# The previous test using COALESCE, which casts both of its arguments to the
+# least restrictive type
+select coalesce(t.arr[1], ROW(9, 9)) as v from (select ARRAY[ROW(1, 2)] as
arr) as t;
++--------+
+| V |
++--------+
+| {1, 2} |
++--------+
+(1 row)
+
+!ok
+
+# COALESCE over a ROW
+select coalesce(t.r, ROW(9, 9)) as v from (select ROW(1, 2) as r) as t;
++--------+
+| V |
++--------+
+| {1, 2} |
++--------+
+(1 row)
+
+!ok
+
# End struct.iq