Skip to content

Commit

Permalink
Implement like/ilike etc for StringViewArray (#5931)
Browse files Browse the repository at this point in the history
* like for string view array

* fix bug

* update doc

* update tests
  • Loading branch information
XiangpengHao authored Jun 24, 2024
1 parent 3139a08 commit 66bada5
Show file tree
Hide file tree
Showing 3 changed files with 417 additions and 254 deletions.
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 @@ -569,6 +569,20 @@ impl StringViewArray {
pub fn to_binary_view(self) -> BinaryViewArray {
unsafe { BinaryViewArray::new_unchecked(self.views, self.buffers, self.nulls) }
}

/// 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 string 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 StringArray)
// 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,
})
}
}

impl From<Vec<&str>> for StringViewArray {
Expand Down
Loading

0 comments on commit 66bada5

Please sign in to comment.