Skip to content

Commit

Permalink
Add BooleanArray::into_parts method (#5191)
Browse files Browse the repository at this point in the history
* Add `BooleanArray::into_parts` method

* Add a test

* Remove `DataType` from returned tuple
  • Loading branch information
mbrobbel authored Dec 8, 2023
1 parent c821ae7 commit a43e82c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions arrow-array/src/array/boolean_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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());
}
}

0 comments on commit a43e82c

Please sign in to comment.