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§
Source§impl<K> FixedSizeBinaryDictionaryBuilder<K>where
K: ArrowDictionaryKeyType,
impl<K> FixedSizeBinaryDictionaryBuilder<K>where
K: ArrowDictionaryKeyType,
Sourcepub fn with_capacity(
keys_capacity: usize,
value_capacity: usize,
byte_width: i32,
) -> Self
pub fn with_capacity( keys_capacity: usize, value_capacity: usize, byte_width: i32, ) -> Self
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
Source§impl<K> FixedSizeBinaryDictionaryBuilder<K>where
K: ArrowDictionaryKeyType,
impl<K> FixedSizeBinaryDictionaryBuilder<K>where
K: ArrowDictionaryKeyType,
fn get_or_insert_key( &mut self, value: impl AsRef<[u8]>, ) -> Result<K::Native, ArrowError>
Sourcepub fn append(
&mut self,
value: impl AsRef<[u8]>,
) -> Result<K::Native, ArrowError>
pub fn append( &mut self, value: impl AsRef<[u8]>, ) -> Result<K::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.
Sourcepub fn append_null(&mut self)
pub fn append_null(&mut self)
Appends a null slot into the builder
Sourcepub 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
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> ArrayBuilder for FixedSizeBinaryDictionaryBuilder<K>where
K: ArrowDictionaryKeyType,
impl<K> ArrayBuilder for FixedSizeBinaryDictionaryBuilder<K>where
K: ArrowDictionaryKeyType,
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.