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

github-merge-queue[bot] pushed a commit to branch 
gh-readonly-queue/main/pr-12253-d65329d3e71f4276ce41c8675446d178cecfc1fa
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git

commit e3167536ad6059589a9e9fc58ca48534d3e229ff
Author: RIchard Baah <[email protected]>
AuthorDate: Mon Nov 16 19:46:20 2026 +0000

    fix(arrow-string): handle dictionaries without values (#12253)
    
    # Which issue does this PR close?
    
    - Closes #12243.
    
    # Rationale for this change
    
    String predicate kernels call `normalized_keys` for dictionary operands.
    That method intentionally panics when the values array is empty, but a
    valid dictionary can have no values when every key is null. These inputs
    should produce null results instead of panicking.
    
    # What changes are included in this PR?
    
    Handle empty dictionary values in the shared UTF-8 and binary predicate
    paths and return a correctly sized null result. This also removes the
    empty run-end encoded workaround because the underlying dictionary path
    now handles it.
    
    # Are these changes tested?
    
    Tests cover UTF-8 and binary dictionaries in both operand positions,
    scalar dictionaries, zero-row dictionaries, and empty run-end encoded
    inputs.
    
    # Are there any significant user-facing changes?
    
    No.
---
 arrow-string/src/binary_like.rs | 11 ++++++
 arrow-string/src/like.rs        | 81 +++++++++++++++++++++++++++++++++++++----
 2 files changed, 84 insertions(+), 8 deletions(-)

diff --git a/arrow-string/src/binary_like.rs b/arrow-string/src/binary_like.rs
index 7cc7a962f9..8e2954c2ce 100644
--- a/arrow-string/src/binary_like.rs
+++ b/arrow-string/src/binary_like.rs
@@ -53,6 +53,17 @@ pub(crate) fn binary_apply<'a, T: BinaryArrayType<'a> + 'a>(
     r_v: Option<&'a dyn AnyDictionaryArray>,
 ) -> Result<BooleanArray, ArrowError> {
     let l_len = l_v.map_or_else(|| l.len(), |l| l.len());
+    // A valid dictionary without values can only contain null keys.
+    if l_v.is_some_and(|dict| dict.values().is_empty())
+        || r_v.is_some_and(|dict| dict.values().is_empty())
+    {
+        let len = if l_s {
+            r_v.map_or_else(|| r.len(), |r| r.len())
+        } else {
+            l_len
+        };
+        return Ok(BooleanArray::new_null(len));
+    }
     if r_s {
         let idx = match r_v {
             Some(dict) if dict.null_count() != 0 => return 
Ok(BooleanArray::new_null(l_len)),
diff --git a/arrow-string/src/like.rs b/arrow-string/src/like.rs
index f23c987cde..abd8388da5 100644
--- a/arrow-string/src/like.rs
+++ b/arrow-string/src/like.rs
@@ -327,14 +327,6 @@ fn run_end_encoded_op(
         Ok(expand_runs(left, &like_op(op, &run_values(left), rhs)?))
     } else if left_is_scalar {
         Ok(expand_runs(right, &like_op(op, lhs, &run_values(right))?))
-    } else if left.is_empty() {
-        // The dictionary kernels panic on a dictionary without values, so 
match the
-        // run values instead. They are empty too, and like_op still checks 
their types.
-        let left_values = left_is_ree.then(|| run_values(left));
-        let right_values = right_is_ree.then(|| run_values(right));
-        let lhs: &dyn Datum = left_values.as_ref().map_or(lhs, |values| 
values);
-        let rhs: &dyn Datum = right_values.as_ref().map_or(rhs, |values| 
values);
-        like_op(op, lhs, rhs)
     } else {
         // Rows of two arrays need not share run boundaries, so look up each 
row
         // through a dictionary view, which does not copy the values.
@@ -424,6 +416,17 @@ fn string_apply<'a, T: StringArrayType<'a> + 'a>(
     r_v: Option<&'a dyn AnyDictionaryArray>,
 ) -> Result<BooleanArray, ArrowError> {
     let l_len = l_v.map_or_else(|| l.len(), |l| l.len());
+    // A valid dictionary without values can only contain null keys.
+    if l_v.is_some_and(|dict| dict.values().is_empty())
+        || r_v.is_some_and(|dict| dict.values().is_empty())
+    {
+        let len = if l_s {
+            r_v.map_or_else(|| r.len(), |r| r.len())
+        } else {
+            l_len
+        };
+        return Ok(BooleanArray::new_null(len));
+    }
     if r_s {
         let idx = match r_v {
             Some(dict) if dict.null_count() != 0 => return 
Ok(BooleanArray::new_null(l_len)),
@@ -1738,6 +1741,68 @@ mod tests {
         }
     }
 
+    #[test]
+    fn test_utf8_dictionary_empty_values() {
+        let dictionary = DictionaryArray::<Int8Type>::try_new(
+            Int8Array::from(vec![None, None]),
+            Arc::new(StringArray::from(Vec::<&str>::new())),
+        )
+        .unwrap();
+        let patterns = StringArray::from(vec!["a%", "b%"]);
+
+        assert_eq!(
+            like(&dictionary, &patterns).unwrap(),
+            BooleanArray::new_null(2)
+        );
+        assert_eq!(
+            like(&patterns, &dictionary).unwrap(),
+            BooleanArray::new_null(2)
+        );
+
+        let scalar_dictionary = DictionaryArray::<Int8Type>::try_new(
+            Int8Array::from(vec![None]),
+            Arc::new(StringArray::from(Vec::<&str>::new())),
+        )
+        .unwrap();
+        assert_eq!(
+            like(&Scalar::new(&scalar_dictionary), &patterns).unwrap(),
+            BooleanArray::new_null(2)
+        );
+        assert_eq!(
+            like(&patterns, &Scalar::new(&scalar_dictionary)).unwrap(),
+            BooleanArray::new_null(2)
+        );
+
+        let empty_dictionary = DictionaryArray::<Int8Type>::try_new(
+            Int8Array::from(Vec::<Option<i8>>::new()),
+            Arc::new(StringArray::from(Vec::<&str>::new())),
+        )
+        .unwrap();
+        assert_eq!(
+            like(&empty_dictionary, 
&StringArray::from(Vec::<&str>::new())).unwrap(),
+            BooleanArray::new_null(0)
+        );
+    }
+
+    #[test]
+    fn test_binary_dictionary_empty_values() {
+        let dictionary = DictionaryArray::<Int8Type>::try_new(
+            Int8Array::from(vec![None, None]),
+            Arc::new(BinaryArray::from(Vec::<&[u8]>::new())),
+        )
+        .unwrap();
+        let patterns = BinaryArray::from(vec![b"a".as_slice(), 
b"b".as_slice()]);
+
+        assert_eq!(
+            starts_with(&dictionary, &patterns).unwrap(),
+            BooleanArray::new_null(2)
+        );
+        assert_eq!(
+            starts_with(&patterns, &dictionary).unwrap(),
+            BooleanArray::new_null(2)
+        );
+    }
+
     #[test]
     fn test_run_end_encoded_sliced() {
         // Logical rows after the slice: ["arrow", null, null, "Parquet", 
"Parquet"].

Reply via email to