Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion rust/arrow/src/array/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,16 @@ impl<'a> MutableArrayData<'a> {
/// `use_nulls` is a flag used to optimize insertions. It should be `false` if the only source of nulls
/// are the arrays themselves and `true` if the user plans to call [MutableArrayData::extend_nulls].
/// In other words, if `use_nulls` is `false`, calling [MutableArrayData::extend_nulls] should not be used.
pub fn new(arrays: Vec<&'a ArrayData>, use_nulls: bool, capacity: usize) -> Self {
pub fn new(arrays: Vec<&'a ArrayData>, mut use_nulls: bool, capacity: usize) -> Self {
let data_type = arrays[0].data_type();
use crate::datatypes::*;

// if any of the arrays has nulls, insertions from any array requires setting bits
// as there is at least one array with nulls.
if arrays.iter().any(|array| array.null_count() > 0) {
use_nulls = true;
};

let buffers = match &data_type {
DataType::Boolean => {
let bytes = bit_util::ceil(capacity, 8);
Expand Down Expand Up @@ -614,6 +620,26 @@ mod tests {
assert_eq!(result, expected);
}

#[test]
fn test_multiple_with_nulls() {
let array1 = StringArray::from(vec!["hello", "world"]).data();
let array2 = StringArray::from(vec![Some("1"), None]).data();

let arrays = vec![array1.as_ref(), array2.as_ref()];

let mut mutable = MutableArrayData::new(arrays, false, 5);

mutable.extend(0, 0, 2);
mutable.extend(1, 0, 2);

let result = mutable.freeze();
let result = StringArray::from(Arc::new(result));

let expected =
StringArray::from(vec![Some("hello"), Some("world"), Some("1"), None]);
assert_eq!(result, expected);
}

#[test]
fn test_string_null_offset_nulls() {
let array =
Expand Down