ARROW-12425: [Rust] Fix new_null_array dictionary creation
It is my understanding that an arrow array should always have a backing values array, even if the content is all nulls. new_null_array currently violates this as it doesn't allocate the backing store for DictionaryArrays. This causes the concat kernel, and possibly others, to panic with index violations
Signed-off-by: Raphael Taylor-Davies <r.taylordavies@googlemail.com>
Closes #10072 from tustvold/null-dictionary-creation
Authored-by: Raphael Taylor-Davies <r.taylordavies@googlemail.com>
Signed-off-by: Andrew Lamb <andrew@nerdnetworks.org>
diff --git a/rust/arrow/src/array/array.rs b/rust/arrow/src/array/array.rs
index 63d41df..95a3117 100644
--- a/rust/arrow/src/array/array.rs
+++ b/rust/arrow/src/array/array.rs
@@ -421,14 +421,17 @@
DataType::Union(_) => {
unimplemented!("Creating null Union array not yet supported")
}
- DataType::Dictionary(_, value) => {
+ DataType::Dictionary(key, value) => {
+ let keys = new_null_array(key, length);
+ let keys = keys.data();
+
make_array(ArrayData::new(
data_type.clone(),
length,
Some(length),
- Some(MutableBuffer::new_null(length).into()),
+ keys.null_buffer().cloned(),
0,
- vec![MutableBuffer::new(0).into()], // values are empty
+ keys.buffers().into(),
vec![new_empty_array(value.as_ref()).data().clone()],
))
}
@@ -629,5 +632,9 @@
let null_array = new_null_array(array.data_type(), 9);
assert_eq!(&array, &null_array);
+ assert_eq!(
+ array.data().buffers()[0].len(),
+ null_array.data().buffers()[0].len()
+ );
}
}