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

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


The following commit(s) were added to refs/heads/active_release by this push:
     new 486d5a3  fix: Comparisons against scalar slices (#741) (#756)
486d5a3 is described below

commit 486d5a3280445632c3253af27bc0e30f8ddd9cc3
Author: Andrew Lamb <[email protected]>
AuthorDate: Thu Sep 9 16:28:00 2021 -0400

    fix: Comparisons against scalar slices (#741) (#756)
    
    Co-authored-by: Ben Chambers <[email protected]>
---
 arrow/src/compute/kernels/comparison.rs | 37 ++++++++++++++++++++++++++++++---
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/arrow/src/compute/kernels/comparison.rs 
b/arrow/src/compute/kernels/comparison.rs
index 8b7718f..49d0aca 100644
--- a/arrow/src/compute/kernels/comparison.rs
+++ b/arrow/src/compute/kernels/comparison.rs
@@ -122,8 +122,12 @@ macro_rules! compare_op_primitive {
 }
 
 macro_rules! compare_op_scalar {
-    ($left: expr, $right:expr, $op:expr) => {{
-        let null_bit_buffer = $left.data().null_buffer().cloned();
+    ($left:expr, $right:expr, $op:expr) => {{
+        let null_bit_buffer = $left
+            .data()
+            .null_buffer()
+            .map(|b| b.bit_slice($left.offset(), $left.len()));
+
         // Safety:
         // `i < $left.len()`
         let comparison =
@@ -146,7 +150,10 @@ macro_rules! compare_op_scalar {
 
 macro_rules! compare_op_scalar_primitive {
     ($left: expr, $right:expr, $op:expr) => {{
-        let null_bit_buffer = $left.data().null_buffer().cloned();
+        let null_bit_buffer = $left
+            .data()
+            .null_buffer()
+            .map(|b| b.bit_slice($left.offset(), $left.len()));
 
         let mut values = MutableBuffer::from_len_zeroed(($left.len() + 7) / 8);
         let lhs_chunks_iter = $left.values().chunks_exact(8);
@@ -1186,6 +1193,18 @@ mod tests {
     }
 
     #[test]
+    fn test_primitive_array_eq_scalar_with_slice() {
+        let a = Int32Array::from(vec![Some(1), None, Some(2), Some(3)]);
+        let a = a.slice(1, 3);
+        let a: &Int32Array = as_primitive_array(&a);
+        let a_eq = eq_scalar(a, 2).unwrap();
+        assert_eq!(
+            a_eq,
+            BooleanArray::from(vec![None, Some(true), Some(false)])
+        );
+    }
+
+    #[test]
     fn test_primitive_array_neq() {
         cmp_i64!(
             neq,
@@ -1529,6 +1548,18 @@ mod tests {
         };
     }
 
+    #[test]
+    fn test_utf8_eq_scalar_on_slice() {
+        let a = StringArray::from(vec![Some("hi"), None, Some("hello"), 
Some("world")]);
+        let a = a.slice(1, 3);
+        let a = as_string_array(&a);
+        let a_eq = eq_utf8_scalar(a, "hello").unwrap();
+        assert_eq!(
+            a_eq,
+            BooleanArray::from(vec![None, Some(true), Some(false)])
+        );
+    }
+
     macro_rules! test_utf8_scalar {
         ($test_name:ident, $left:expr, $right:expr, $op:expr, $expected:expr) 
=> {
             #[test]

Reply via email to