Struct arrow::array::UnionBuilder
source · [−]pub struct UnionBuilder { /* private fields */ }
Expand description
Builder type for creating a new UnionArray
.
Example: Dense Memory Layout
use arrow::array::UnionBuilder;
use arrow::datatypes::{Float64Type, Int32Type};
let mut builder = UnionBuilder::new_dense(3);
builder.append::<Int32Type>("a", 1).unwrap();
builder.append::<Float64Type>("b", 3.0).unwrap();
builder.append::<Int32Type>("a", 4).unwrap();
let union = builder.build().unwrap();
assert_eq!(union.type_id(0), 0_i8);
assert_eq!(union.type_id(1), 1_i8);
assert_eq!(union.type_id(2), 0_i8);
assert_eq!(union.value_offset(0), 0_i32);
assert_eq!(union.value_offset(1), 0_i32);
assert_eq!(union.value_offset(2), 1_i32);
Example: Sparse Memory Layout
use arrow::array::UnionBuilder;
use arrow::datatypes::{Float64Type, Int32Type};
let mut builder = UnionBuilder::new_sparse(3);
builder.append::<Int32Type>("a", 1).unwrap();
builder.append::<Float64Type>("b", 3.0).unwrap();
builder.append::<Int32Type>("a", 4).unwrap();
let union = builder.build().unwrap();
assert_eq!(union.type_id(0), 0_i8);
assert_eq!(union.type_id(1), 1_i8);
assert_eq!(union.type_id(2), 0_i8);
assert_eq!(union.value_offset(0), 0_i32);
assert_eq!(union.value_offset(1), 1_i32);
assert_eq!(union.value_offset(2), 2_i32);
Implementations
sourceimpl UnionBuilder
impl UnionBuilder
sourcepub fn new_sparse(capacity: usize) -> Self
pub fn new_sparse(capacity: usize) -> Self
Creates a new sparse array builder.
sourcepub fn append_null<T: ArrowPrimitiveType>(
&mut self,
type_name: &str
) -> Result<()>
pub fn append_null<T: ArrowPrimitiveType>(
&mut self,
type_name: &str
) -> Result<()>
Appends a null to this builder, encoding the null in the array
of the type_name
child / field.
Since UnionArray
encodes nulls as an entry in its children
(it doesn’t have a validity bitmap itself), and where the null
is part of the final array, appending a NULL requires
specifying which field (child) to use.
sourcepub fn append<T: ArrowPrimitiveType>(
&mut self,
type_name: &str,
v: T::Native
) -> Result<()>
pub fn append<T: ArrowPrimitiveType>(
&mut self,
type_name: &str,
v: T::Native
) -> Result<()>
Appends a value to this builder.
sourcepub fn build(self) -> Result<UnionArray>
pub fn build(self) -> Result<UnionArray>
Builds this builder creating a new UnionArray
.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for UnionBuilder
impl Send for UnionBuilder
impl Sync for UnionBuilder
impl Unpin for UnionBuilder
impl UnwindSafe for UnionBuilder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more