This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch 59_maintenance
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/59_maintenance by this push:
new cc8196a7da [59_maintenance] fix(arrow-array): use the field's type id
in dense union logical_nulls (#11680)
cc8196a7da is described below
commit cc8196a7da2c3b963606992d9485f9f014745e62
Author: Jeffrey Vo <[email protected]>
AuthorDate: Tue Oct 20 04:01:45 2026 +0900
[59_maintenance] fix(arrow-array): use the field's type id in dense union
logical_nulls (#11680)
- Backport https://github.com/apache/arrow-rs/pull/11643
- For inclusion in https://github.com/apache/arrow-rs/issues/11664
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 5ba7b947c7..cc94adb958 100644
--- a/arrow-array/src/array/union_array.rs
+++ b/arrow-array/src/array/union_array.rs
@@ -798,18 +798,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();
@@ -2027,6 +2032,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 = [