Struct FixedSizeBinaryDictionaryBuilder
pub struct FixedSizeBinaryDictionaryBuilder<K>where
K: ArrowDictionaryKeyType,{
state: RandomState,
dedup: HashTable<usize>,
keys_builder: PrimitiveBuilder<K>,
values_builder: FixedSizeBinaryBuilder,
byte_width: i32,
}
Expand description
Builder for DictionaryArray
of FixedSizeBinaryArray
The output array has a dictionary of unique, fixed-size binary values. The builder handles deduplication.
§Example
// Build 3 byte FixedBinaryArrays
let byte_width = 3;
let mut builder = FixedSizeBinaryDictionaryBuilder::<Int8Type>::new(3);
builder.append("abc").unwrap();
builder.append_null();
builder.append(b"def").unwrap();
builder.append(b"def").unwrap(); // duplicate value
// Result is a Dictionary Array
let array = builder.finish();
let dict_array = array.as_any().downcast_ref::<DictionaryArray<Int8Type>>().unwrap();
// The array represents "abc", null, "def", "def"
assert_eq!(array.keys().len(), 4);
// but there are only 2 unique values
assert_eq!(array.values().len(), 2);
let values = dict_array.values().as_any().downcast_ref::<FixedSizeBinaryArray>().unwrap();
assert_eq!(values.value(0), "abc".as_bytes());
assert_eq!(values.value(1), "def".as_bytes());
Fields§
§state: RandomState
§dedup: HashTable<usize>
§keys_builder: PrimitiveBuilder<K>
§values_builder: FixedSizeBinaryBuilder
§byte_width: i32
Implementations§
§impl<K> FixedSizeBinaryDictionaryBuilder<K>where
K: ArrowDictionaryKeyType,
impl<K> FixedSizeBinaryDictionaryBuilder<K>where
K: ArrowDictionaryKeyType,
pub fn new(byte_width: i32) -> FixedSizeBinaryDictionaryBuilder<K>
pub fn new(byte_width: i32) -> FixedSizeBinaryDictionaryBuilder<K>
Creates a new FixedSizeBinaryDictionaryBuilder
pub fn with_capacity(
keys_capacity: usize,
value_capacity: usize,
byte_width: i32,
) -> FixedSizeBinaryDictionaryBuilder<K>
pub fn with_capacity( keys_capacity: usize, value_capacity: usize, byte_width: i32, ) -> FixedSizeBinaryDictionaryBuilder<K>
Creates a new FixedSizeBinaryDictionaryBuilder
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
byte_width
: the byte width for individual values in the values array
§impl<K> FixedSizeBinaryDictionaryBuilder<K>where
K: ArrowDictionaryKeyType,
impl<K> FixedSizeBinaryDictionaryBuilder<K>where
K: ArrowDictionaryKeyType,
pub fn append(
&mut self,
value: impl AsRef<[u8]>,
) -> Result<<K as ArrowPrimitiveType>::Native, ArrowError>
pub fn append( &mut self, value: impl AsRef<[u8]>, ) -> Result<<K as ArrowPrimitiveType>::Native, ArrowError>
Append a 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.
pub fn append_null(&mut self)
pub fn append_null(&mut self)
Appends a null slot into the builder
pub fn append_value(&mut self, value: impl AsRef<[u8]>)
pub fn append_value(&mut self, value: impl AsRef<[u8]>)
Infallibly append a value to this builder
§Panics
Panics if the resulting length of the dictionary values array would exceed T::Native::MAX
pub fn finish(&mut self) -> DictionaryArray<K>
pub fn finish(&mut self) -> DictionaryArray<K>
Builds the DictionaryArray
and reset this builder.
pub fn finish_cloned(&self) -> DictionaryArray<K>
pub fn finish_cloned(&self) -> DictionaryArray<K>
Builds the DictionaryArray
without resetting the builder.
Trait Implementations§
§impl<K> ArrayBuilder for FixedSizeBinaryDictionaryBuilder<K>where
K: ArrowDictionaryKeyType,
impl<K> ArrayBuilder for FixedSizeBinaryDictionaryBuilder<K>where
K: ArrowDictionaryKeyType,
§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Returns the builder as an mutable Any
reference.
§fn into_box_any(self: Box<FixedSizeBinaryDictionaryBuilder<K>>) -> Box<dyn Any>
fn into_box_any(self: Box<FixedSizeBinaryDictionaryBuilder<K>>) -> Box<dyn Any>
Returns the boxed builder as a box of Any
.
§fn finish_cloned(&self) -> Arc<dyn Array>
fn finish_cloned(&self) -> Arc<dyn Array>
Builds the array without resetting the builder.