This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new 5bf8912651 [arrow-string]: add `like::eq_ascii_ignore_case` kernel 
(#9871)
5bf8912651 is described below

commit 5bf891265174ee85310582f9d1fa3be844d38fdd
Author: albertlockett <[email protected]>
AuthorDate: Wed May 6 09:33:14 2026 -0400

    [arrow-string]: add `like::eq_ascii_ignore_case` kernel (#9871)
    
    # Which issue does this PR close?
    
    <!--
    We generally require a GitHub issue to be filed for all bug fixes and
    enhancements and this helps us generate change logs for our releases.
    You can link an issue to this PR using the GitHub syntax.
    -->
    
    - Closes https://github.com/apache/arrow-rs/issues/9870
    
    # Rationale for this change
    
    <!--
    Why are you proposing this change? If this is already explained clearly
    in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand
    your changes and offer better suggestions for fixes.
    -->
    
    Users might wish to have a mechanism to do check if two strings are
    equal in a case-insensitive way. We already have some machinery to do
    this in the arrow-string crate (in the `predicate` module). This PR
    exposes a function so it can be invoked easily.
    
    # What changes are included in this PR?
    
    <!--
    There is no need to duplicate the description in the issue here but it
    is sometimes worth providing a summary of the individual changes in this
    PR.
    -->
    
    Adds a function `like::eq_ascii_ignore_case` to the arrow-string crate
    that performs a case-insensitive equals check on two string arrays.
    
    # Are these changes tested?
    
    <!--
    We typically require tests for all PRs in order to:
    1. Prevent the code from being accidentally broken by subsequent changes
    2. Serve as another way to document the expected behavior of the code
    
    If tests are not included in your PR, please explain why (for example,
    are they covered by existing tests)?
    
    If this PR claims a performance improvement, please include evidence
    such as benchmark results.
    -->
    
    yes unit tests
    
    
    # Are there any user-facing changes?
    
    <!--
    If there are user-facing changes then we may require documentation to be
    updated before approving the PR.
    
    If there are any breaking changes to public APIs, please call them out.
    -->
    
    Yes this function is public
---
 arrow-string/src/like.rs | 59 ++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 55 insertions(+), 4 deletions(-)

diff --git a/arrow-string/src/like.rs b/arrow-string/src/like.rs
index 55fe292ecb..2ad7e1cfd9 100644
--- a/arrow-string/src/like.rs
+++ b/arrow-string/src/like.rs
@@ -15,7 +15,11 @@
 // specific language governing permissions and limitations
 // under the License.
 
-//! Provide SQL's LIKE operators for Arrow's string arrays
+//! String predicate kernels for Arrow arrays.
+//!
+//! Provides SQL `LIKE`/`ILIKE` kernels as well as related
+//! string predicates such as `contains`, `starts_with`, `ends_with`, and
+//! ASCII case-insensitive equality.
 
 use crate::predicate::Predicate;
 
@@ -34,6 +38,7 @@ pub(crate) enum Op {
     Like(bool),
     ILike(bool),
     Contains,
+    EqIgnoreAsciiCase,
     StartsWith,
     EndsWith,
 }
@@ -46,6 +51,7 @@ impl std::fmt::Display for Op {
             Op::ILike(false) => write!(f, "ILIKE"),
             Op::ILike(true) => write!(f, "NILIKE"),
             Op::Contains => write!(f, "CONTAINS"),
+            Op::EqIgnoreAsciiCase => write!(f, "EQ_IGNORE_ASCII_CASE"),
             Op::StartsWith => write!(f, "STARTS_WITH"),
             Op::EndsWith => write!(f, "ENDS_WITH"),
         }
@@ -124,7 +130,7 @@ pub fn nilike(left: &dyn Datum, right: &dyn Datum) -> 
Result<BooleanArray, Arrow
 /// # Example
 /// ```
 /// # use arrow_array::{StringArray, BooleanArray};
-/// # use arrow_string::like::{like, starts_with};
+/// # use arrow_string::like::starts_with;
 /// let strings = StringArray::from(vec!["arrow-rs", "arrow-rs", "arrow-rs", 
"Parquet"]);
 /// let patterns = StringArray::from(vec!["arr", "arrow", "arrow-cpp", "p"]);
 ///
@@ -150,7 +156,7 @@ pub fn starts_with(left: &dyn Datum, right: &dyn Datum) -> 
Result<BooleanArray,
 /// # Example
 /// ```
 /// # use arrow_array::{StringArray, BooleanArray};
-/// # use arrow_string::like::{ends_with, like, starts_with};
+/// # use arrow_string::like::ends_with;
 /// let strings = StringArray::from(vec!["arrow-rs", "arrow-rs",  "Parquet"]);
 /// let patterns = StringArray::from(vec!["arr", "-rs", "t"]);
 ///
@@ -176,7 +182,7 @@ pub fn ends_with(left: &dyn Datum, right: &dyn Datum) -> 
Result<BooleanArray, Ar
 /// # Example
 /// ```
 /// # use arrow_array::{StringArray, BooleanArray};
-/// # use arrow_string::like::{contains, like, starts_with};
+/// # use arrow_string::like::contains;
 /// let strings = StringArray::from(vec!["arrow-rs", "arrow-rs", "arrow-rs", 
"Parquet"]);
 /// let patterns = StringArray::from(vec!["arr", "-rs", "arrow-cpp", "X"]);
 ///
@@ -187,6 +193,30 @@ pub fn contains(left: &dyn Datum, right: &dyn Datum) -> 
Result<BooleanArray, Arr
     like_op(Op::Contains, left, right)
 }
 
+/// Perform equality check on two arrays using an ASCII case-insensitive match.
+///
+/// `left` and `right` must be the same type, and one of
+/// - Utf8
+/// - LargeUtf8
+/// - Utf8View
+///
+/// # Example
+/// ```
+/// # use arrow_array::{StringArray, BooleanArray};
+/// # use arrow_string::like::eq_ignore_ascii_case;
+/// let strings = StringArray::from(vec!["arrow", "rs", "arrow-rS", 
"Parquet"]);
+/// let patterns = StringArray::from(vec!["ARROW", "rS", "ARROW-rs", "arrow"]);
+///
+/// let result = eq_ignore_ascii_case(&strings, &patterns).unwrap();
+/// assert_eq!(result, BooleanArray::from(vec![true, true, true, false]));
+/// ```
+pub fn eq_ignore_ascii_case(
+    left: &dyn Datum,
+    right: &dyn Datum,
+) -> Result<BooleanArray, ArrowError> {
+    like_op(Op::EqIgnoreAsciiCase, left, right)
+}
+
 fn like_op(op: Op, lhs: &dyn Datum, rhs: &dyn Datum) -> Result<BooleanArray, 
ArrowError> {
     use arrow_schema::DataType::*;
     let (l, l_s) = lhs.get();
@@ -328,6 +358,7 @@ fn op_scalar<'a, T: StringArrayType<'a>>(
         Op::Like(neg) => Predicate::like(r)?.evaluate_array(l, neg),
         Op::ILike(neg) => Predicate::ilike(r, l.is_ascii())?.evaluate_array(l, 
neg),
         Op::Contains => Predicate::contains(r).evaluate_array(l, false),
+        Op::EqIgnoreAsciiCase => Predicate::IEqAscii(r).evaluate_array(l, 
false),
         Op::StartsWith => Predicate::StartsWith(r).evaluate_array(l, false),
         Op::EndsWith => Predicate::EndsWith(r).evaluate_array(l, false),
     };
@@ -362,6 +393,10 @@ fn op_binary<'a>(
         Op::Like(neg) => binary_predicate(l, r, neg, Predicate::like),
         Op::ILike(neg) => binary_predicate(l, r, neg, |s| Predicate::ilike(s, 
false)),
         Op::Contains => Ok(l.zip(r).map(|(l, r)| Some(str_contains(l?, 
r?))).collect()),
+        Op::EqIgnoreAsciiCase => Ok(l
+            .zip(r)
+            .map(|(l, r)| Some(Predicate::IEqAscii(l?).evaluate(r?)))
+            .collect()),
         Op::StartsWith => Ok(l
             .zip(r)
             .map(|(l, r)| Some(Predicate::StartsWith(r?).evaluate(l?)))
@@ -1394,6 +1429,22 @@ mod tests {
         vec![true, false, true, true, true]
     );
 
+    test_utf8!(
+        test_utf8_array_eq_ignore_ascii_case,
+        vec!["arrow", "arrow", "arrow", "arrow", "parquet", "parquet"],
+        vec!["arrow", "ARROW", "arro", "aRrOw", "arrow", "ARROW"],
+        eq_ignore_ascii_case,
+        vec![true, true, false, true, false, false]
+    );
+
+    test_utf8_scalar!(
+        test_utf8_array_eq_ignore_ascii_case_scalar,
+        vec!["arrow", "aRrOW", "arro", "ARROW", "parquet", "PARQUET"],
+        "arrow",
+        eq_ignore_ascii_case,
+        vec![true, true, false, true, false, false]
+    );
+
     #[test]
     fn test_dict_like_kernels() {
         let data = vec![

Reply via email to