Skip to content

Commit 50bdaa5

Browse files
tustvoldalamb
authored andcommitted
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 <[email protected]> Closes #10072 from tustvold/null-dictionary-creation Authored-by: Raphael Taylor-Davies <[email protected]> Signed-off-by: Andrew Lamb <[email protected]>
1 parent e0edc95 commit 50bdaa5

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

rust/arrow/src/array/array.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,14 +421,17 @@ pub fn new_null_array(data_type: &DataType, length: usize) -> ArrayRef {
421421
DataType::Union(_) => {
422422
unimplemented!("Creating null Union array not yet supported")
423423
}
424-
DataType::Dictionary(_, value) => {
424+
DataType::Dictionary(key, value) => {
425+
let keys = new_null_array(key, length);
426+
let keys = keys.data();
427+
425428
make_array(ArrayData::new(
426429
data_type.clone(),
427430
length,
428431
Some(length),
429-
Some(MutableBuffer::new_null(length).into()),
432+
keys.null_buffer().cloned(),
430433
0,
431-
vec![MutableBuffer::new(0).into()], // values are empty
434+
keys.buffers().into(),
432435
vec![new_empty_array(value.as_ref()).data().clone()],
433436
))
434437
}
@@ -629,5 +632,9 @@ mod tests {
629632

630633
let null_array = new_null_array(array.data_type(), 9);
631634
assert_eq!(&array, &null_array);
635+
assert_eq!(
636+
array.data().buffers()[0].len(),
637+
null_array.data().buffers()[0].len()
638+
);
632639
}
633640
}

0 commit comments

Comments
 (0)