-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-10103: [Rust] Add contains kernel #8280
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ | |
| use crate::array::*; | ||
| #[cfg(feature = "simd")] | ||
| use crate::bitmap::Bitmap; | ||
| use crate::buffer::{buffer_bin_and, Buffer}; | ||
| use crate::buffer::{buffer_bin_and, buffer_bin_or, Buffer}; | ||
| #[cfg(feature = "simd")] | ||
| use crate::datatypes::*; | ||
| use crate::error::{ArrowError, Result}; | ||
|
|
@@ -71,6 +71,47 @@ pub(super) fn combine_option_bitmap( | |
| } | ||
| } | ||
|
|
||
| /// Compares the null bitmaps of two arrays using a bitwise `or` operation. | ||
| /// | ||
| /// This function is useful when implementing operations on higher level arrays. | ||
| pub(super) fn compare_option_bitmap( | ||
| left_data: &ArrayDataRef, | ||
| right_data: &ArrayDataRef, | ||
| len_in_bits: usize, | ||
| ) -> Result<Option<Buffer>> { | ||
| let left_offset_in_bits = left_data.offset(); | ||
| let right_offset_in_bits = right_data.offset(); | ||
|
|
||
| let left = left_data.null_buffer(); | ||
| let right = right_data.null_buffer(); | ||
|
|
||
| if (left.is_some() && left_offset_in_bits % 8 != 0) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity: is this true in general, or is for these (this and above) implementation, that uses this assumption?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm trying to solve this problem in #8262 The issue is that |
||
| || (right.is_some() && right_offset_in_bits % 8 != 0) | ||
| { | ||
| return Err(ArrowError::ComputeError( | ||
| "Cannot compare option bitmaps that are not byte-aligned.".to_string(), | ||
| )); | ||
| } | ||
|
|
||
| let left_offset = left_offset_in_bits / 8; | ||
| let right_offset = right_offset_in_bits / 8; | ||
|
|
||
| match left { | ||
| None => match right { | ||
| None => Ok(None), | ||
| Some(r) => Ok(Some(r.slice(right_offset))), | ||
| }, | ||
| Some(l) => match right { | ||
| None => Ok(Some(l.slice(left_offset))), | ||
|
|
||
| Some(r) => { | ||
| let len = ceil(len_in_bits, 8); | ||
| Ok(Some(buffer_bin_or(&l, left_offset, &r, right_offset, len))) | ||
| } | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| /// Takes/filters a list array's inner data using the offsets of the list array. | ||
| /// | ||
| /// Where a list array has indices `[0,2,5,10]`, taking indices of `[2,0]` returns | ||
|
|
@@ -208,6 +249,8 @@ mod tests { | |
| let none_bitmap = make_data_with_null_bit_buffer(8, 0, None); | ||
| let some_bitmap = | ||
| make_data_with_null_bit_buffer(8, 0, Some(Buffer::from([0b01001010]))); | ||
| let inverse_bitmap = | ||
| make_data_with_null_bit_buffer(8, 0, Some(Buffer::from([0b10110101]))); | ||
| assert_eq!( | ||
| None, | ||
| combine_option_bitmap(&none_bitmap, &none_bitmap, 8).unwrap() | ||
|
|
@@ -224,6 +267,39 @@ mod tests { | |
| Some(Buffer::from([0b01001010])), | ||
| combine_option_bitmap(&some_bitmap, &some_bitmap, 8,).unwrap() | ||
| ); | ||
| assert_eq!( | ||
| Some(Buffer::from([0b0])), | ||
| combine_option_bitmap(&some_bitmap, &inverse_bitmap, 8,).unwrap() | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_compare_option_bitmap() { | ||
| let none_bitmap = make_data_with_null_bit_buffer(8, 0, None); | ||
| let some_bitmap = | ||
| make_data_with_null_bit_buffer(8, 0, Some(Buffer::from([0b01001010]))); | ||
| let inverse_bitmap = | ||
| make_data_with_null_bit_buffer(8, 0, Some(Buffer::from([0b10110101]))); | ||
| assert_eq!( | ||
| None, | ||
| compare_option_bitmap(&none_bitmap, &none_bitmap, 8).unwrap() | ||
| ); | ||
| assert_eq!( | ||
| Some(Buffer::from([0b01001010])), | ||
| compare_option_bitmap(&some_bitmap, &none_bitmap, 8).unwrap() | ||
| ); | ||
| assert_eq!( | ||
| Some(Buffer::from([0b01001010])), | ||
| compare_option_bitmap(&none_bitmap, &some_bitmap, 8,).unwrap() | ||
| ); | ||
| assert_eq!( | ||
| Some(Buffer::from([0b01001010])), | ||
| compare_option_bitmap(&some_bitmap, &some_bitmap, 8,).unwrap() | ||
| ); | ||
| assert_eq!( | ||
| Some(Buffer::from([0b11111111])), | ||
| compare_option_bitmap(&some_bitmap, &inverse_bitmap, 8,).unwrap() | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.