Struct arrow::array::UnionBuilder

source ·
pub struct UnionBuilder { /* private fields */ }
Expand description

Builder for UnionArray

Example: Dense Memory Layout


let mut builder = UnionBuilder::new_dense();
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);
assert_eq!(union.type_id(1), 1);
assert_eq!(union.type_id(2), 0);

assert_eq!(union.value_offset(0), 0);
assert_eq!(union.value_offset(1), 0);
assert_eq!(union.value_offset(2), 1);

Example: Sparse Memory Layout


let mut builder = UnionBuilder::new_sparse();
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);
assert_eq!(union.type_id(1), 1);
assert_eq!(union.type_id(2), 0);

assert_eq!(union.value_offset(0), 0);
assert_eq!(union.value_offset(1), 1);
assert_eq!(union.value_offset(2), 2);

Implementations§

source§

impl UnionBuilder

source

pub fn new_dense() -> UnionBuilder

Creates a new dense array builder.

source

pub fn new_sparse() -> UnionBuilder

Creates a new sparse array builder.

source

pub fn with_capacity_dense(capacity: usize) -> UnionBuilder

Creates a new dense array builder with capacity.

source

pub fn with_capacity_sparse(capacity: usize) -> UnionBuilder

Creates a new sparse array builder with capacity.

source

pub fn append_null<T>(&mut self, type_name: &str) -> Result<(), ArrowError>

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.

source

pub fn append<T>( &mut self, type_name: &str, v: <T as ArrowPrimitiveType>::Native ) -> Result<(), ArrowError>

Appends a value to this builder.

source

pub fn build(self) -> Result<UnionArray, ArrowError>

Builds this builder creating a new UnionArray.

Trait Implementations§

source§

impl Debug for UnionBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.