Struct arrow_array::builder::GenericByteDictionaryBuilder
source · pub struct GenericByteDictionaryBuilder<K, T>where
K: ArrowDictionaryKeyType,
T: ByteArrayType,{ /* private fields */ }
Expand description
Generic array builder for DictionaryArray
that stores generic byte values.
For example to map a set of byte indices to String values. Note that
the use of a HashMap
here will not scale to very large arrays or
result in an ordered dictionary.
Implementations§
source§impl<K, T> GenericByteDictionaryBuilder<K, T>where
K: ArrowDictionaryKeyType,
T: ByteArrayType,
impl<K, T> GenericByteDictionaryBuilder<K, T>where
K: ArrowDictionaryKeyType,
T: ByteArrayType,
sourcepub fn with_capacity(
keys_capacity: usize,
value_capacity: usize,
data_capacity: usize
) -> Self
pub fn with_capacity(
keys_capacity: usize,
value_capacity: usize,
data_capacity: usize
) -> Self
Creates a new GenericByteDictionaryBuilder
with the provided capacities
keys_capacity
: the number of keys, i.e. length of array to build
value_capacity
: the number of distinct dictionary values, i.e. size of dictionary
data_capacity
: the total number of bytes of all distinct bytes in the dictionary
sourcepub fn new_with_dictionary(
keys_capacity: usize,
dictionary_values: &GenericByteArray<T>
) -> Result<Self, ArrowError>
pub fn new_with_dictionary(
keys_capacity: usize,
dictionary_values: &GenericByteArray<T>
) -> Result<Self, ArrowError>
Creates a new GenericByteDictionaryBuilder
from a keys capacity and a dictionary
which is initialized with the given values.
The indices of those dictionary values are used as keys.
Example
let dictionary_values = StringArray::from(vec![None, Some("abc"), Some("def")]);
let mut builder = StringDictionaryBuilder::new_with_dictionary(3, &dictionary_values).unwrap();
builder.append("def").unwrap();
builder.append_null();
builder.append("abc").unwrap();
let dictionary_array = builder.finish();
let keys = dictionary_array.keys();
assert_eq!(keys, &Int16Array::from(vec![Some(2), None, Some(1)]));
source§impl<K, T> GenericByteDictionaryBuilder<K, T>where
K: ArrowDictionaryKeyType,
T: ByteArrayType,
impl<K, T> GenericByteDictionaryBuilder<K, T>where
K: ArrowDictionaryKeyType,
T: ByteArrayType,
sourcepub fn append(
&mut self,
value: impl AsRef<T::Native>
) -> Result<K::Native, ArrowError>
pub fn append(
&mut self,
value: impl AsRef<T::Native>
) -> Result<K::Native, ArrowError>
Append a primitive value to the array. Return an existing index if already present in the values array or a new index if the value is appended to the values array.
Returns an error if the new index would overflow the key type.
sourcepub fn append_null(&mut self)
pub fn append_null(&mut self)
Appends a null slot into the builder
sourcepub fn finish(&mut self) -> DictionaryArray<K>
pub fn finish(&mut self) -> DictionaryArray<K>
Builds the DictionaryArray
and reset this builder.
sourcepub fn finish_cloned(&self) -> DictionaryArray<K>
pub fn finish_cloned(&self) -> DictionaryArray<K>
Builds the DictionaryArray
without resetting the builder.
Trait Implementations§
source§impl<K, T> ArrayBuilder for GenericByteDictionaryBuilder<K, T>where
K: ArrowDictionaryKeyType,
T: ByteArrayType,
impl<K, T> ArrayBuilder for GenericByteDictionaryBuilder<K, T>where
K: ArrowDictionaryKeyType,
T: ByteArrayType,
source§fn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
Returns the builder as an mutable Any
reference.
source§fn finish_cloned(&self) -> ArrayRef
fn finish_cloned(&self) -> ArrayRef
Builds the array without resetting the builder.