Struct arrow::array::StringDictionaryBuilder[][src]

pub struct StringDictionaryBuilder<K> where
    K: ArrowDictionaryKeyType
{ /* fields omitted */ }
Expand description

Array builder for DictionaryArray that stores Strings. 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.

use arrow::{
  array::{
    Int8Array, StringArray,
    PrimitiveBuilder, StringBuilder, StringDictionaryBuilder,
  },
  datatypes::Int8Type,
};

// Create a dictionary array indexed by bytes whose values are Strings.
// It can thus hold up to 256 distinct string values.

let key_builder = PrimitiveBuilder::<Int8Type>::new(100);
let value_builder = StringBuilder::new(100);
let mut builder = StringDictionaryBuilder::new(key_builder, value_builder);

// The builder builds the dictionary value by value
builder.append("abc").unwrap();
builder.append_null().unwrap();
builder.append("def").unwrap();
builder.append("def").unwrap();
builder.append("abc").unwrap();
let array = builder.finish();

assert_eq!(
  array.keys(),
  &Int8Array::from(vec![Some(0), None, Some(1), Some(1), Some(0)])
);

// Values are polymorphic and so require a downcast.
let av = array.values();
let ava: &StringArray = av.as_any().downcast_ref::<StringArray>().unwrap();

assert_eq!(ava.value(0), "abc");
assert_eq!(ava.value(1), "def");

Implementations

impl<K> StringDictionaryBuilder<K> where
    K: ArrowDictionaryKeyType
[src]

pub fn new(
    keys_builder: PrimitiveBuilder<K>,
    values_builder: StringBuilder
) -> Self
[src]

Creates a new StringDictionaryBuilder from a keys builder and a value builder.

pub fn new_with_dictionary(
    keys_builder: PrimitiveBuilder<K>,
    dictionary_values: &StringArray
) -> Result<Self>
[src]

Creates a new StringDictionaryBuilder from a keys builder and a dictionary which is initialized with the given values. The indices of those dictionary values are used as keys.

Example

use arrow::datatypes::Int16Type;
use arrow::array::{StringArray, StringDictionaryBuilder, PrimitiveBuilder, Int16Array};
use std::convert::TryFrom;

let dictionary_values = StringArray::from(vec![None, Some("abc"), Some("def")]);

let mut builder = StringDictionaryBuilder::new_with_dictionary(PrimitiveBuilder::<Int16Type>::new(3), &dictionary_values).unwrap();
builder.append("def").unwrap();
builder.append_null().unwrap();
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)]));

impl<K> StringDictionaryBuilder<K> where
    K: ArrowDictionaryKeyType
[src]

pub fn append(&mut self, value: impl AsRef<str>) -> Result<K::Native>[src]

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.

pub fn append_null(&mut self) -> Result<()>[src]

pub fn finish(&mut self) -> DictionaryArray<K>[src]

Builds the DictionaryArray and reset this builder.

Trait Implementations

impl<K> ArrayBuilder for StringDictionaryBuilder<K> where
    K: ArrowDictionaryKeyType
[src]

fn as_any(&self) -> &dyn Any[src]

Returns the builder as an non-mutable Any reference.

fn as_any_mut(&mut self) -> &mut dyn Any[src]

Returns the builder as an mutable Any reference.

fn into_box_any(self: Box<Self>) -> Box<dyn Any>[src]

Returns the boxed builder as a box of Any.

fn len(&self) -> usize[src]

Returns the number of array slots in the builder

fn is_empty(&self) -> bool[src]

Returns whether the number of array slots is zero

fn finish(&mut self) -> ArrayRef[src]

Builds the array and reset this builder.

impl<K: Debug> Debug for StringDictionaryBuilder<K> where
    K: ArrowDictionaryKeyType,
    K::Native: Debug
[src]

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

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

pub fn vzip(self) -> V