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 a43e82c630 Add `BooleanArray::into_parts` method (#5191)
a43e82c630 is described below

commit a43e82c630f507d6afc4fc62031bb2336d29f37d
Author: Matthijs Brobbel <m1brob...@gmail.com>
AuthorDate: Fri Dec 8 15:53:29 2023 +0100

    Add `BooleanArray::into_parts` method (#5191)
    
    * Add `BooleanArray::into_parts` method
    
    * Add a test
    
    * Remove `DataType` from returned tuple
---
 arrow-array/src/array/boolean_array.rs | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/arrow-array/src/array/boolean_array.rs 
b/arrow-array/src/array/boolean_array.rs
index a778dc92ea..fe374d9657 100644
--- a/arrow-array/src/array/boolean_array.rs
+++ b/arrow-array/src/array/boolean_array.rs
@@ -254,6 +254,11 @@ impl BooleanArray {
         });
         Self::new(values, nulls)
     }
+
+    /// Deconstruct this array into its constituent parts
+    pub fn into_parts(self) -> (BooleanBuffer, Option<NullBuffer>) {
+        (self.values, self.nulls)
+    }
 }
 
 impl Array for BooleanArray {
@@ -618,4 +623,21 @@ mod tests {
             assert_eq!(b.false_count(), expected_false);
         }
     }
+
+    #[test]
+    fn test_into_parts() {
+        let boolean_array = [Some(true), None, Some(false)]
+            .into_iter()
+            .collect::<BooleanArray>();
+        let (values, nulls) = boolean_array.into_parts();
+        assert_eq!(values.values(), &[0b0000_0001]);
+        assert!(nulls.is_some());
+        assert_eq!(nulls.unwrap().buffer().as_slice(), &[0b0000_0101]);
+
+        let boolean_array =
+            BooleanArray::from(vec![false, false, false, false, false, false, 
false, true]);
+        let (values, nulls) = boolean_array.into_parts();
+        assert_eq!(values.values(), &[0b1000_0000]);
+        assert!(nulls.is_none());
+    }
 }

Reply via email to