This is an automated email from the ASF dual-hosted git repository.
dheres 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 7bcc1ad988 implement append_n for BooleanBuilder (#6646)
7bcc1ad988 is described below
commit 7bcc1ad988498def843180c6a4c95f9732f31a4b
Author: delamarch3 <[email protected]>
AuthorDate: Tue Oct 29 19:55:51 2024 +0000
implement append_n for BooleanBuilder (#6646)
---
arrow-array/src/builder/boolean_builder.rs | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/arrow-array/src/builder/boolean_builder.rs
b/arrow-array/src/builder/boolean_builder.rs
index 3a2caf80cf..60ed86ce80 100644
--- a/arrow-array/src/builder/boolean_builder.rs
+++ b/arrow-array/src/builder/boolean_builder.rs
@@ -123,6 +123,13 @@ impl BooleanBuilder {
self.null_buffer_builder.append_n_non_nulls(v.len());
}
+ /// Appends n `additional` bits of value `v` into the buffer
+ #[inline]
+ pub fn append_n(&mut self, additional: usize, v: bool) {
+ self.values_builder.append_n(additional, v);
+ self.null_buffer_builder.append_n_non_nulls(additional);
+ }
+
/// Appends values from a slice of type `T` and a validity boolean slice.
///
/// Returns an error if the slices are of different lengths
@@ -325,4 +332,18 @@ mod tests {
&[false, false, true, false, false, true, true, false]
)
}
+
+ #[test]
+ fn test_boolean_array_builder_append_n() {
+ let mut builder = BooleanBuilder::new();
+ builder.append_n(3, true);
+ builder.append_n(2, false);
+ let array = builder.finish();
+ assert_eq!(3, array.true_count());
+ assert_eq!(2, array.false_count());
+ assert_eq!(0, array.null_count());
+
+ let values = array.iter().map(|x| x.unwrap()).collect::<Vec<_>>();
+ assert_eq!(&values, &[true, true, true, false, false])
+ }
}