Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure take_fixed_size_list can handle null indices #5170

Merged
Merged
Changes from 2 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
21 changes: 20 additions & 1 deletion arrow-select/src/take.rs
westonpace marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,9 @@ where
.ok_or_else(|| ArrowError::ComputeError("Cast to usize failed".to_string()))?;
let start = list.value_offset(index) as <UInt32Type as ArrowPrimitiveType>::Native;

values.extend(start..start + length);
values.extend((start..start + length).map(Some));
westonpace marked this conversation as resolved.
Show resolved Hide resolved
} else {
values.extend((0..length).map(|_| None));
westonpace marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -1985,6 +1987,23 @@ mod tests {
assert_eq!(&values, &[Some(23), Some(4), None, None])
}

#[test]
fn test_take_fixed_size_list_null_indices() {
let indices = Int32Array::new(vec![0, 1].into(), Some(NullBuffer::from(vec![true, false])));
westonpace marked this conversation as resolved.
Show resolved Hide resolved
let values = Arc::new(Int32Array::from(vec![0, 1, 2, 3]));
let arr_field = Arc::new(Field::new("item", values.data_type().clone(), true));
let values = FixedSizeListArray::try_new(arr_field, 2, values, None).unwrap();

let r = take(&values, &indices, None).unwrap();
let values = r
.as_fixed_size_list()
.values()
.as_primitive::<Int32Type>()
.into_iter()
.collect::<Vec<_>>();
assert_eq!(&values, &[Some(0), Some(1), None, None])
westonpace marked this conversation as resolved.
Show resolved Hide resolved
}

#[test]
fn test_take_bytes_null_indices() {
let indices = Int32Array::new(
Expand Down
Loading