You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by tu...@apache.org on 2023/07/31 13:53:19 UTC

[arrow-rs] branch master updated: fix(data): create child arrays of correct length when building a sparse union null array (#4601)

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 d1fb2c6a0a fix(data): create child arrays of correct length when building a sparse union null array (#4601)
d1fb2c6a0a is described below

commit d1fb2c6a0a07d3e28fb41287c0b5e1dc8fc032e5
Author: Tomoaki Kawada <ka...@kmckk.co.jp>
AuthorDate: Mon Jul 31 22:53:14 2023 +0900

    fix(data): create child arrays of correct length when building a sparse union null array (#4601)
    
    * test: validate built arrays in `test_null_union`
    
    * fix(data): create child arrays of correct length when building a sparse union null array
---
 arrow-array/src/array/mod.rs | 2 ++
 arrow-data/src/data/mod.rs   | 9 ++++++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/arrow-array/src/array/mod.rs b/arrow-array/src/array/mod.rs
index 9312770644..0157279dfe 100644
--- a/arrow-array/src/array/mod.rs
+++ b/arrow-array/src/array/mod.rs
@@ -841,6 +841,8 @@ mod tests {
                 assert_eq!(a.null_count(), 1);
                 assert!(a.is_null(0))
             }
+
+            array.to_data().validate_full().unwrap();
         }
     }
 
diff --git a/arrow-data/src/data/mod.rs b/arrow-data/src/data/mod.rs
index 32aae1e92a..50643b90e8 100644
--- a/arrow-data/src/data/mod.rs
+++ b/arrow-data/src/data/mod.rs
@@ -634,9 +634,12 @@ impl ArrayData {
                     let children = f
                         .iter()
                         .enumerate()
-                        .map(|(idx, (_, f))| match idx {
-                            0 => Self::new_null(f.data_type(), len),
-                            _ => Self::new_empty(f.data_type()),
+                        .map(|(idx, (_, f))| {
+                            if idx == 0 || *mode == UnionMode::Sparse {
+                                Self::new_null(f.data_type(), len)
+                            } else {
+                                Self::new_empty(f.data_type())
+                            }
                         })
                         .collect();