You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by al...@apache.org on 2021/09/10 09:38:48 UTC
[arrow-rs] branch active_release updated: fix: new_null_array for
structs (#736) (#760)
This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch active_release
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/active_release by this push:
new b77b135 fix: new_null_array for structs (#736) (#760)
b77b135 is described below
commit b77b135c7932c129e2888c6b04bc345e300a33bc
Author: Andrew Lamb <an...@nerdnetworks.org>
AuthorDate: Fri Sep 10 05:38:45 2021 -0400
fix: new_null_array for structs (#736) (#760)
Co-authored-by: Ben Chambers <35...@users.noreply.github.com>
---
arrow/src/array/array.rs | 36 +++++++++++++++++++++++++-----------
1 file changed, 25 insertions(+), 11 deletions(-)
diff --git a/arrow/src/array/array.rs b/arrow/src/array/array.rs
index d715bc4..21fda04 100644
--- a/arrow/src/array/array.rs
+++ b/arrow/src/array/array.rs
@@ -440,18 +440,15 @@ pub fn new_null_array(data_type: &DataType, length: usize) -> ArrayRef {
.clone(),
],
)),
- DataType::Struct(fields) => make_array(ArrayData::new(
- data_type.clone(),
- length,
- Some(length),
- Some(MutableBuffer::new_null(length).into()),
- 0,
- vec![],
- fields
+ DataType::Struct(fields) => {
+ let fields: Vec<_> = fields
.iter()
- .map(|field| ArrayData::new_empty(field.data_type()))
- .collect(),
- )),
+ .map(|field| (field.clone(), new_null_array(field.data_type(), length)))
+ .collect();
+
+ let null_buffer = MutableBuffer::new_null(length);
+ Arc::new(StructArray::from((fields, null_buffer.into())))
+ }
DataType::Union(_) => {
unimplemented!("Creating null Union array not yet supported")
}
@@ -634,6 +631,23 @@ mod tests {
}
#[test]
+ fn test_null_struct() {
+ let struct_type =
+ DataType::Struct(vec![Field::new("data", DataType::Int64, false)]);
+ let array = new_null_array(&struct_type, 9);
+
+ let a = array.as_any().downcast_ref::<StructArray>().unwrap();
+ assert_eq!(a.len(), 9);
+ assert_eq!(a.column(0).len(), 9);
+ for i in 0..9 {
+ assert!(a.is_null(i));
+ }
+
+ // Make sure we can slice the resulting array.
+ a.slice(0, 5);
+ }
+
+ #[test]
fn test_null_variable_sized() {
let array = new_null_array(&DataType::Utf8, 9);
let a = array.as_any().downcast_ref::<StringArray>().unwrap();