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

tustvold 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 dfb642809e support NullArray un arith/boolean kernel (#4566)
dfb642809e is described below

commit dfb642809e93c2c1b8343692f4e4b3080000f988
Author: Miklos Szots <[email protected]>
AuthorDate: Tue Jul 25 14:36:54 2023 +0200

    support NullArray un arith/boolean kernel (#4566)
    
    * support NullArray un arith/boolean kernel
    
    * prettify based on feedback
---
 arrow-arith/src/boolean.rs | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/arrow-arith/src/boolean.rs b/arrow-arith/src/boolean.rs
index 04c9fb2290..61e591d516 100644
--- a/arrow-arith/src/boolean.rs
+++ b/arrow-arith/src/boolean.rs
@@ -25,7 +25,7 @@
 use arrow_array::*;
 use arrow_buffer::buffer::{bitwise_bin_op_helper, 
bitwise_quaternary_op_helper};
 use arrow_buffer::{BooleanBuffer, NullBuffer};
-use arrow_schema::ArrowError;
+use arrow_schema::{ArrowError, DataType};
 
 /// Logical 'and' boolean values with Kleene logic
 ///
@@ -312,6 +312,10 @@ pub fn not(left: &BooleanArray) -> Result<BooleanArray, 
ArrowError> {
 /// ```
 pub fn is_null(input: &dyn Array) -> Result<BooleanArray, ArrowError> {
     let values = match input.nulls() {
+        // NullArray has no nulls buffer yet all values are null
+        None if input.data_type() == &DataType::Null => {
+            BooleanBuffer::new_set(input.len())
+        }
         None => BooleanBuffer::new_unset(input.len()),
         Some(nulls) => !nulls.inner(),
     };
@@ -332,6 +336,10 @@ pub fn is_null(input: &dyn Array) -> Result<BooleanArray, 
ArrowError> {
 /// ```
 pub fn is_not_null(input: &dyn Array) -> Result<BooleanArray, ArrowError> {
     let values = match input.nulls() {
+        // NullArray has no nulls buffer yet all values are null
+        None if input.data_type() == &DataType::Null => {
+            BooleanBuffer::new_unset(input.len())
+        }
         None => BooleanBuffer::new_set(input.len()),
         Some(n) => n.inner().clone(),
     };
@@ -871,4 +879,28 @@ mod tests {
         assert_eq!(expected, res);
         assert!(res.nulls().is_none());
     }
+
+    #[test]
+    fn test_null_array_is_null() {
+        let a = NullArray::new(3);
+
+        let res = is_null(&a).unwrap();
+
+        let expected = BooleanArray::from(vec![true, true, true]);
+
+        assert_eq!(expected, res);
+        assert!(res.nulls().is_none());
+    }
+
+    #[test]
+    fn test_null_array_is_not_null() {
+        let a = NullArray::new(3);
+
+        let res = is_not_null(&a).unwrap();
+
+        let expected = BooleanArray::from(vec![false, false, false]);
+
+        assert_eq!(expected, res);
+        assert!(res.nulls().is_none());
+    }
 }

Reply via email to