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

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


The following commit(s) were added to refs/heads/57_maintenance by this push:
     new ecd340dccb [57_maintenance] fix(arrow-array): use the field's type id 
in dense union logical_nulls (#11810)
ecd340dccb is described below

commit ecd340dccb3fd7b57af671223601db5568e2cb3b
Author: Jeffrey Vo <[email protected]>
AuthorDate: Fri Oct 23 00:10:42 2026 +0900

    [57_maintenance] fix(arrow-array): use the field's type id in dense union 
logical_nulls (#11810)
    
    - Backport https://github.com/apache/arrow-rs/pull/11643
    - For inclusion in https://github.com/apache/arrow-rs/issues/11666
    
    Cherry-pick of
    
https://github.com/apache/arrow-rs/commit/24c53c7b0803d32575e5bcb302bf78065ded31b6
    
    Co-authored-by: Chang Yong Lik <[email protected]>
---
 arrow-array/src/array/union_array.rs | 46 ++++++++++++++++++++++++++----------
 1 file changed, 34 insertions(+), 12 deletions(-)

diff --git a/arrow-array/src/array/union_array.rs 
b/arrow-array/src/array/union_array.rs
index f7adaa9568..73e3045faa 100644
--- a/arrow-array/src/array/union_array.rs
+++ b/arrow-array/src/array/union_array.rs
@@ -794,18 +794,23 @@ unsafe impl Array for UnionArray {
         };
 
         if fields.len() <= 1 {
-            return self.fields.iter().find_map(|field_opt| {
-                field_opt
-                    .as_ref()
-                    .and_then(|field| field.logical_nulls())
-                    .map(|logical_nulls| {
-                        if self.is_dense() {
-                            self.gather_nulls(vec![(0, logical_nulls)]).into()
-                        } else {
-                            logical_nulls
-                        }
-                    })
-            });
+            return self
+                .fields
+                .iter()
+                .enumerate()
+                .find_map(|(type_id, field_opt)| {
+                    field_opt
+                        .as_ref()
+                        .and_then(|field| field.logical_nulls())
+                        .map(|logical_nulls| {
+                            if self.is_dense() {
+                                self.gather_nulls(vec![(type_id as i8, 
logical_nulls)])
+                                    .into()
+                            } else {
+                                logical_nulls
+                            }
+                        })
+                });
         }
 
         let logical_nulls = self.fields_logical_nulls();
@@ -2012,6 +2017,23 @@ mod tests {
         assert_eq!(expected, array.gather_nulls(array.fields_logical_nulls()));
     }
 
+    #[test]
+    fn test_dense_union_one_field_nonzero_type_id_logical_nulls() {
+        let fields = UnionFields::try_new([5], [Field::new("a", 
DataType::Int32, true)]).unwrap();
+        let child = Arc::new(Int32Array::from(vec![None, Some(1)]));
+        let array = UnionArray::try_new(
+            fields,
+            vec![5, 5, 5].into(),
+            Some(vec![1, 0, 1].into()),
+            vec![child],
+        )
+        .unwrap();
+
+        let expected = NullBuffer::from(vec![true, false, true]);
+        assert_eq!(array.logical_nulls(), Some(expected));
+        assert_eq!(array.logical_null_count(), 1);
+    }
+
     #[test]
     fn test_sparse_union_logical_nulls_mask_all_nulls_skip_one() {
         let fields: UnionFields = [

Reply via email to