From a43e82c630f507d6afc4fc62031bb2336d29f37d Mon Sep 17 00:00:00 2001 From: Matthijs Brobbel Date: Fri, 8 Dec 2023 15:53:29 +0100 Subject: [PATCH] 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 a778dc92ea35..fe374d965714 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) { + (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::(); + 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()); + } }