This is an automated email from the ASF dual-hosted git repository.
alamb 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 5af340c fix: new_null_array for structs (#736)
5af340c is described below
commit 5af340c556c0d765113b5b4683f369790e612ede
Author: Ben Chambers <[email protected]>
AuthorDate: Thu Sep 9 13:02:10 2021 -0700
fix: new_null_array for structs (#736)
---
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 8cbac31..be19fea 100644
--- a/arrow/src/array/array.rs
+++ b/arrow/src/array/array.rs
@@ -448,18 +448,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::Map(field, _keys_sorted) => {
new_null_list_array::<i32>(data_type, field.data_type(), length)
}
@@ -645,6 +642,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();