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

tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new bfe396e3fc Ensure arrays passed to MutableArrayData have same type 
(#5091) (#5092)
bfe396e3fc is described below

commit bfe396e3fcbaf7dd88572986dc538ab5922c088b
Author: Raphael Taylor-Davies <[email protected]>
AuthorDate: Fri Nov 17 16:44:35 2023 +0000

    Ensure arrays passed to MutableArrayData have same type (#5091) (#5092)
---
 arrow-data/src/transform/mod.rs | 8 ++++++++
 arrow/tests/array_transform.rs  | 8 ++++++++
 2 files changed, 16 insertions(+)

diff --git a/arrow-data/src/transform/mod.rs b/arrow-data/src/transform/mod.rs
index af25e9c7e3..268cf10f23 100644
--- a/arrow-data/src/transform/mod.rs
+++ b/arrow-data/src/transform/mod.rs
@@ -354,6 +354,14 @@ impl<'a> MutableArrayData<'a> {
     ) -> Self {
         let data_type = arrays[0].data_type();
 
+        for a in arrays.iter().skip(1) {
+            assert_eq!(
+                data_type,
+                a.data_type(),
+                "Arrays with inconsistent types passed to MutableArrayData"
+            )
+        }
+
         // if any of the arrays has nulls, insertions from any array requires 
setting bits
         // as there is at least one array with nulls.
         let use_nulls = use_nulls | arrays.iter().any(|array| 
array.null_count() > 0);
diff --git a/arrow/tests/array_transform.rs b/arrow/tests/array_transform.rs
index ccf66e1c30..74e2a21273 100644
--- a/arrow/tests/array_transform.rs
+++ b/arrow/tests/array_transform.rs
@@ -975,6 +975,14 @@ fn test_extend_nulls_panic() {
     mutable.extend_nulls(2);
 }
 
+#[test]
+#[should_panic(expected = "Arrays with inconsistent types passed to 
MutableArrayData")]
+fn test_mixed_types() {
+    let a = StringArray::from(vec!["abc", "def"]).to_data();
+    let b = Int32Array::from(vec![1, 2, 3]).to_data();
+    MutableArrayData::new(vec![&a, &b], false, 4);
+}
+
 /*
 // this is an old test used on a meanwhile removed dead code
 // that is still useful when `MutableArrayData` supports fixed-size lists.

Reply via email to