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

add binary support in arrow-string #6926

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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 {
// 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