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

Support Binary arrays in starts_with, ends_with and contains #6926

Merged
merged 14 commits into from
Jan 22, 2025
14 changes: 14 additions & 0 deletions arrow-array/src/array/byte_view_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,20 @@ where
pub type BinaryViewArray = GenericByteViewArray<BinaryViewType>;

impl BinaryViewArray {
/// Returns true if all data within this array is ASCII
pub fn is_ascii(&self) -> bool {
// Alternative (but incorrect): directly check the underlying buffers
// (1) Our binary view might be sparse, i.e., a subset of the buffers,
// so even if the buffer is not ascii, we can still be ascii.
// (2) It is quite difficult to know the range of each buffer (unlike BinaryArray)
// This means that this operation is quite expensive, shall we cache the result?
// i.e. track `is_ascii` in the builder.
self.iter().all(|v| match v {
Some(v) => v.is_ascii(),
None => true,
})
}

/// Convert the [`BinaryViewArray`] to [`StringViewArray`]
/// If items not utf8 data, validate will fail and error returned.
pub fn to_string_view(self) -> Result<StringViewArray, ArrowError> {
Expand Down
10 changes: 10 additions & 0 deletions arrow-array/src/array/fixed_size_binary_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ pub struct FixedSizeBinaryArray {
}

impl FixedSizeBinaryArray {
/// Returns true if all data within this array is ASCII
pub fn is_ascii(&self) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the need to check a binary array for ASCII -- there shouldn't be any optimizations that rely on the data being ASCII

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because I did not want to duplicate the whole like and predicate file I implemented like and this needed for the like impl.

But instead I only implemented the contains, start with, and ends with

// TODO - check if we can do similar to BinaryArray
// as this is expensive
self.iter().all(|v| match v {
Some(v) => v.is_ascii(),
None => true,
})
}

/// Create a new [`FixedSizeBinaryArray`] with `size` element size, panicking on failure
///
/// # Panics
Expand Down
Loading
Loading