This is an automated email from the ASF dual-hosted git repository.
agrove pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new d00c50a ARROW-3688: [Rust] Add append_values for primitive builders
d00c50a is described below
commit d00c50a6ca0d88e3458742091c59f0fc5c2fc7de
Author: Neville Dipale <[email protected]>
AuthorDate: Mon Jun 8 21:42:05 2020 -0600
ARROW-3688: [Rust] Add append_values for primitive builders
This implements `append_values` for primitive builders, which allows for
pushing a number of values and their validity buffer at the same time.
Closes #7306 from nevi-me/ARROW-3688
Authored-by: Neville Dipale <[email protected]>
Signed-off-by: Andy Grove <[email protected]>
---
rust/arrow/src/array/builder.rs | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/rust/arrow/src/array/builder.rs b/rust/arrow/src/array/builder.rs
index a8b4222..546f944 100644
--- a/rust/arrow/src/array/builder.rs
+++ b/rust/arrow/src/array/builder.rs
@@ -569,6 +569,21 @@ impl<T: ArrowPrimitiveType> PrimitiveBuilder<T> {
Ok(())
}
+ /// Appends values from a slice of type `T` and a validity boolean slice
+ pub fn append_values(
+ &mut self,
+ values: &[T::Native],
+ is_valid: &[bool],
+ ) -> Result<()> {
+ if values.len() != is_valid.len() {
+ return Err(ArrowError::InvalidArgumentError(
+ "Value and validity lengths must be equal".to_string(),
+ ));
+ }
+ self.bitmap_builder.append_slice(is_valid)?;
+ self.values_builder.append_slice(values)
+ }
+
/// Builds the `PrimitiveArray` and reset this builder.
pub fn finish(&mut self) -> PrimitiveArray<T> {
let len = self.len();
@@ -1984,6 +1999,32 @@ mod tests {
}
#[test]
+ fn test_append_values() -> Result<()> {
+ let mut a = Int8Builder::new(0);
+ a.append_value(1)?;
+ a.append_null()?;
+ a.append_value(-2)?;
+ assert_eq!(a.len(), 3);
+
+ // append values
+ let values = &[1, 2, 3, 4];
+ let is_valid = &[true, true, false, true];
+ a.append_values(values, is_valid)?;
+
+ assert_eq!(a.len(), 7);
+ let array = a.finish();
+ assert_eq!(array.value(0), 1);
+ assert_eq!(array.is_null(1), true);
+ assert_eq!(array.value(2), -2);
+ assert_eq!(array.value(3), 1);
+ assert_eq!(array.value(4), 2);
+ assert_eq!(array.is_null(5), true);
+ assert_eq!(array.value(6), 4);
+
+ Ok(())
+ }
+
+ #[test]
fn test_write_bytes() {
let mut b = BooleanBufferBuilder::new(4);
b.append(false).unwrap();