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

Cherry pick implement take kernel for null arrays to active_release #944

Merged
merged 1 commit into from
Nov 12, 2021
Merged
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
43 changes: 43 additions & 0 deletions arrow/src/compute/kernels/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,17 @@ where
.unwrap();
Ok(Arc::new(take_fixed_size_binary(values, indices)?))
}
DataType::Null => {
// Take applied to a null array produces a null array.
if values.len() >= indices.len() {
// If the existing null array is as big as the indices, we can use a slice of it
// to avoid allocating a new null array.
Ok(values.slice(0, indices.len()))
} else {
// If the existing null array isn't big enough, create a new one.
Ok(new_null_array(&DataType::Null, indices.len()))
}
}
t => unimplemented!("Take not supported for data type {:?}", t),
}
}
Expand Down Expand Up @@ -1813,6 +1824,38 @@ mod tests {
.unwrap();
}

#[test]
fn test_null_array_smaller_than_indices() {
let values = NullArray::new(2);
let indices = UInt32Array::from(vec![Some(0), None, Some(15)]);

let result = take(&values, &indices, None).unwrap();
let expected: ArrayRef = Arc::new(NullArray::new(3));
assert_eq!(&result, &expected);
}

#[test]
fn test_null_array_larger_than_indices() {
let values = NullArray::new(5);
let indices = UInt32Array::from(vec![Some(0), None, Some(15)]);

let result = take(&values, &indices, None).unwrap();
let expected: ArrayRef = Arc::new(NullArray::new(3));
assert_eq!(&result, &expected);
}

#[test]
fn test_null_array_indices_out_of_bounds() {
let values = NullArray::new(5);
let indices = UInt32Array::from(vec![Some(0), None, Some(15)]);

let result = take(&values, &indices, Some(TakeOptions { check_bounds: true }));
assert_eq!(
result.unwrap_err().to_string(),
"Compute error: Array index out of bounds, cannot get item at index 15 from 5 entries"
);
}

#[test]
fn test_take_dict() {
let keys_builder = Int16Builder::new(8);
Expand Down