pub struct UnionBuilder {
len: usize,
fields: BTreeMap<String, FieldData>,
type_id_builder: Int8BufferBuilder,
value_offset_builder: Option<Int32BufferBuilder>,
initial_capacity: usize,
}
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);
Fields§
§len: usize
The current number of slots in the array
fields: BTreeMap<String, FieldData>
Maps field names to FieldData
instances which track the builders for that field
type_id_builder: Int8BufferBuilder
Builder to keep track of type ids
value_offset_builder: Option<Int32BufferBuilder>
Builder to keep track of offsets (None
for sparse unions)
initial_capacity: usize
Implementations§
Source§impl UnionBuilder
impl UnionBuilder
Sourcepub fn new_sparse() -> Self
pub fn new_sparse() -> Self
Creates a new sparse array builder.
Sourcepub fn with_capacity_dense(capacity: usize) -> Self
pub fn with_capacity_dense(capacity: usize) -> Self
Creates a new dense array builder with capacity.
Sourcepub fn with_capacity_sparse(capacity: usize) -> Self
pub fn with_capacity_sparse(capacity: usize) -> Self
Creates a new sparse array builder with capacity.
Sourcepub fn append_null<T: ArrowPrimitiveType>(
&mut self,
type_name: &str,
) -> Result<(), ArrowError>
pub fn append_null<T: ArrowPrimitiveType>( &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.
Sourcepub fn append<T: ArrowPrimitiveType>(
&mut self,
type_name: &str,
v: T::Native,
) -> Result<(), ArrowError>
pub fn append<T: ArrowPrimitiveType>( &mut self, type_name: &str, v: T::Native, ) -> Result<(), ArrowError>
Appends a value to this builder.
fn append_option<T: ArrowPrimitiveType>( &mut self, type_name: &str, v: Option<T::Native>, ) -> Result<(), ArrowError>
Sourcepub fn build(self) -> Result<UnionArray, ArrowError>
pub fn build(self) -> Result<UnionArray, ArrowError>
Builds this builder creating a new UnionArray
.