You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@auron.apache.org by "Copilot (via GitHub)" <gi...@apache.org> on 2026/07/01 03:33:02 UTC

Re: [PR] [AURON #1716] fix string cast array missing null value [auron]

Copilot commented on code in PR #1750:
URL: https://github.com/apache/auron/pull/1750#discussion_r3503116903


##########
spark-extension-shims-spark/src/test/scala/org/apache/auron/AuronQuerySuite.scala:
##########
@@ -1014,4 +1014,76 @@ class AuronQuerySuite extends AuronQueryTest with BaseAuronSQLSuite with AuronSQ
         |FROM t_filter_agg_2289""".stripMargin)
     }
   }
+
+  test("cast array to string") {
+    if (AuronTestUtils.isSparkV31OrGreater) {
+      withTable("t_array") {
+        sql("""
+              |create table t_array using parquet as
+              |select array(1, 2, 3) as arr
+              |union all select array(4, 5)
+              |union all select array(null, 7, null)
+              |""".stripMargin)
+
+        checkSparkAnswerAndOperator("select cast(arr as string) from t_array")
+      }
+    }
+  }
+
+  test("cast nested array to string") {
+    if (AuronTestUtils.isSparkV31OrGreater) {
+      withTable("t_nested_array") {
+        sql("""
+              |create table t_nested_array using parquet as
+              |select array(array(1, 2), array(3, 4, 5)) as arr
+              |union all select array(array(6), array(7, 8))
+              |""".stripMargin)
+
+        checkSparkAnswerAndOperator("select cast(arr as string) from t_nested_array")
+      }
+    }
+  }
+
+  test("cast array with null elements to string") {
+    if (AuronTestUtils.isSparkV31OrGreater) {
+      withTable("t_array_nulls") {
+        sql("""
+              |create table t_array_nulls using parquet as
+              |select array(cast(null as int), cast(null as int)) as arr
+              |union all select array(1, null, 3)
+              |union all select array(null, 2, null, 4)
+              |""".stripMargin)

Review Comment:
   The issue description is specifically about casting an array with a single null element (e.g. array(c1) where c1 is NULL) producing "[null]". This test data doesn't include a single-element null array, so the exact regression scenario isn't covered.



##########
native-engine/datafusion-ext-commons/src/arrow/cast.rs:
##########
@@ -1043,4 +1087,125 @@ mod test {
         );
         Ok(())
     }
+
+    #[test]
+    fn test_array_to_string() {
+        // Create a list array with int32 elements
+        let values = Int32Array::from(vec![
+            Some(1),
+            Some(2),
+            Some(3),
+            None,
+            Some(5),
+            Some(6),
+            None,
+            None,
+        ]);
+        let offsets = OffsetBuffer::new(vec![0, 3, 5, 8].into());
+        let list_array: ArrayRef = Arc::new(ListArray::new(
+            Arc::new(Field::new("item", DataType::Int32, true)),
+            offsets,
+            Arc::new(values),
+            None,
+        ));
+
+        let casted = cast(&list_array, &DataType::Utf8).expect("cast list to utf8 failed");
+        assert_eq!(
+            as_string_array(&casted),
+            &StringArray::from_iter(vec![
+                Some("[1, 2, 3]"),
+                Some("[null, 5]"),
+                Some("[6, null, null]"),
+            ])

Review Comment:
   If a single-null list row is added to the test input, the expected output should also assert the "[null]" rendering to match Spark semantics.



##########
native-engine/datafusion-ext-commons/src/arrow/cast.rs:
##########
@@ -1043,4 +1087,125 @@ mod test {
         );
         Ok(())
     }
+
+    #[test]
+    fn test_array_to_string() {
+        // Create a list array with int32 elements
+        let values = Int32Array::from(vec![
+            Some(1),
+            Some(2),
+            Some(3),
+            None,
+            Some(5),
+            Some(6),
+            None,
+            None,
+        ]);
+        let offsets = OffsetBuffer::new(vec![0, 3, 5, 8].into());

Review Comment:
   This unit test covers null elements but doesn't include the reported edge case of a single-element list containing only NULL. Adding a row for "[null]" would better lock in the regression fix (Spark expects "[null]", not "[]").



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@auron.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org