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

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


The following commit(s) were added to refs/heads/master by this push:
     new 333515f  Add dyn boolean kernels (#1131)
333515f is described below

commit 333515fe767c65359ea82613c5d6d597ea185400
Author: Matthew Turner <[email protected]>
AuthorDate: Wed Jan 5 16:53:32 2022 -0500

    Add dyn boolean kernels (#1131)
    
    * Add dyn bool kernels
    
    * Add tests
    
    * Update error messages
    
    * Update test
    
    * Fix test
    
    * Update doc strings
---
 arrow/src/compute/kernels/comparison.rs | 138 +++++++++++++++++++++++++++++++-
 1 file changed, 134 insertions(+), 4 deletions(-)

diff --git a/arrow/src/compute/kernels/comparison.rs 
b/arrow/src/compute/kernels/comparison.rs
index 191a47f..5be2605 100644
--- a/arrow/src/compute/kernels/comparison.rs
+++ b/arrow/src/compute/kernels/comparison.rs
@@ -1425,7 +1425,7 @@ pub fn neq_dyn_utf8_scalar(left: Arc<dyn Array>, right: 
&str) -> Result<BooleanA
                 dyn_compare_utf8_scalar!(&left, right, key_type, 
neq_utf8_scalar)
             }
             _ => Err(ArrowError::ComputeError(
-                "Kernel only supports Utf8 or LargeUtf8 arrays or 
DictionaryArray with Utf8 or LargeUtf8 values".to_string(),
+                "neq_dyn_utf8_scalar only supports Utf8 or LargeUtf8 arrays or 
DictionaryArray with Utf8 or LargeUtf8 values".to_string(),
             )),
         },
         DataType::Utf8 | DataType::LargeUtf8 => {
@@ -1433,14 +1433,14 @@ pub fn neq_dyn_utf8_scalar(left: Arc<dyn Array>, right: 
&str) -> Result<BooleanA
             neq_utf8_scalar(left, right)
         }
         _ => Err(ArrowError::ComputeError(
-            "Kernel only supports Utf8 or LargeUtf8 arrays".to_string(),
+            "neq_dyn_utf8_scalar only supports Utf8 or LargeUtf8 
arrays".to_string(),
         )),
     };
     result
 }
 
 /// Perform `left == right` operation on an array and a numeric scalar
-/// value. Supports BooleanArrays, and DictionaryArrays that have string values
+/// value. Supports BooleanArrays.
 pub fn eq_dyn_bool_scalar(left: Arc<dyn Array>, right: bool) -> 
Result<BooleanArray> {
     let result = match left.data_type() {
         DataType::Boolean => {
@@ -1448,7 +1448,82 @@ pub fn eq_dyn_bool_scalar(left: Arc<dyn Array>, right: 
bool) -> Result<BooleanAr
             eq_bool_scalar(left, right)
         }
         _ => Err(ArrowError::ComputeError(
-            "Kernel only supports BooleanArray".to_string(),
+            "eq_dyn_bool_scalar only supports BooleanArray".to_string(),
+        )),
+    };
+    result
+}
+
+/// Perform `left < right` operation on an array and a numeric scalar
+/// value. Supports BooleanArrays.
+pub fn lt_dyn_bool_scalar(left: Arc<dyn Array>, right: bool) -> 
Result<BooleanArray> {
+    let result = match left.data_type() {
+        DataType::Boolean => {
+            let left = as_boolean_array(&left);
+            lt_bool_scalar(left, right)
+        }
+        _ => Err(ArrowError::ComputeError(
+            "lt_dyn_bool_scalar only supports BooleanArray".to_string(),
+        )),
+    };
+    result
+}
+
+/// Perform `left > right` operation on an array and a numeric scalar
+/// value. Supports BooleanArrays.
+pub fn gt_dyn_bool_scalar(left: Arc<dyn Array>, right: bool) -> 
Result<BooleanArray> {
+    let result = match left.data_type() {
+        DataType::Boolean => {
+            let left = as_boolean_array(&left);
+            gt_bool_scalar(left, right)
+        }
+        _ => Err(ArrowError::ComputeError(
+            "gt_dyn_bool_scalar only supports BooleanArray".to_string(),
+        )),
+    };
+    result
+}
+
+/// Perform `left <= right` operation on an array and a numeric scalar
+/// value. Supports BooleanArrays.
+pub fn lt_eq_dyn_bool_scalar(left: Arc<dyn Array>, right: bool) -> 
Result<BooleanArray> {
+    let result = match left.data_type() {
+        DataType::Boolean => {
+            let left = as_boolean_array(&left);
+            lt_eq_bool_scalar(left, right)
+        }
+        _ => Err(ArrowError::ComputeError(
+            "lt_eq_dyn_bool_scalar only supports BooleanArray".to_string(),
+        )),
+    };
+    result
+}
+
+/// Perform `left >= right` operation on an array and a numeric scalar
+/// value. Supports BooleanArrays.
+pub fn gt_eq_dyn_bool_scalar(left: Arc<dyn Array>, right: bool) -> 
Result<BooleanArray> {
+    let result = match left.data_type() {
+        DataType::Boolean => {
+            let left = as_boolean_array(&left);
+            gt_eq_bool_scalar(left, right)
+        }
+        _ => Err(ArrowError::ComputeError(
+            "gt_eq_dyn_bool_scalar only supports BooleanArray".to_string(),
+        )),
+    };
+    result
+}
+
+/// Perform `left != right` operation on an array and a numeric scalar
+/// value. Supports BooleanArrays.
+pub fn neq_dyn_bool_scalar(left: Arc<dyn Array>, right: bool) -> 
Result<BooleanArray> {
+    let result = match left.data_type() {
+        DataType::Boolean => {
+            let left = as_boolean_array(&left);
+            neq_bool_scalar(left, right)
+        }
+        _ => Err(ArrowError::ComputeError(
+            "neq_dyn_bool_scalar only supports BooleanArray".to_string(),
         )),
     };
     result
@@ -3599,4 +3674,59 @@ mod tests {
             BooleanArray::from(vec![Some(false), Some(true), Some(false)])
         );
     }
+
+    #[test]
+    fn test_lt_dyn_bool_scalar() {
+        let array = BooleanArray::from(vec![Some(true), Some(false), 
Some(true), None]);
+        let array = Arc::new(array);
+        let a_eq = lt_dyn_bool_scalar(array, false).unwrap();
+        assert_eq!(
+            a_eq,
+            BooleanArray::from(vec![Some(false), Some(false), Some(false), 
None])
+        );
+    }
+
+    #[test]
+    fn test_gt_dyn_bool_scalar() {
+        let array = BooleanArray::from(vec![true, false, true]);
+        let array = Arc::new(array);
+        let a_eq = gt_dyn_bool_scalar(array, false).unwrap();
+        assert_eq!(
+            a_eq,
+            BooleanArray::from(vec![Some(true), Some(false), Some(true)])
+        );
+    }
+
+    #[test]
+    fn test_lt_eq_dyn_bool_scalar() {
+        let array = BooleanArray::from(vec![true, false, true]);
+        let array = Arc::new(array);
+        let a_eq = lt_eq_dyn_bool_scalar(array, false).unwrap();
+        assert_eq!(
+            a_eq,
+            BooleanArray::from(vec![Some(false), Some(true), Some(false)])
+        );
+    }
+
+    #[test]
+    fn test_gt_eq_dyn_bool_scalar() {
+        let array = BooleanArray::from(vec![true, false, true]);
+        let array = Arc::new(array);
+        let a_eq = gt_eq_dyn_bool_scalar(array, false).unwrap();
+        assert_eq!(
+            a_eq,
+            BooleanArray::from(vec![Some(true), Some(true), Some(true)])
+        );
+    }
+
+    #[test]
+    fn test_neq_dyn_bool_scalar() {
+        let array = BooleanArray::from(vec![true, false, true]);
+        let array = Arc::new(array);
+        let a_eq = neq_dyn_bool_scalar(array, false).unwrap();
+        assert_eq!(
+            a_eq,
+            BooleanArray::from(vec![Some(true), Some(false), Some(true)])
+        );
+    }
 }

Reply via email to