Skip to main content

Dictionary

Struct Dictionary 

Source
pub struct Dictionary<K, V> { /* private fields */ }
Expand description

Marker for an arrow Dictionary column, e.g. Dictionary<i32, Utf8>.

Think of Dictionary<K, V> as a column of V, dictionary-compressed: the encoding is a storage detail, and the element values are those of V (e.g. &str), looked up through the dictionary keys. K is the integer key type (i8i64, u8u64) — a space/size trade-off, never user-visible.

§Nullability

Since Dictionary<K, V> is logically a column of V, row nullability works like for any other column: Option<Dictionary<K, V>> means the rows may be null (arrow encodes this in the validity bitmap of the keys). Dictionary<Option<K>, V> would be meaningless: the keys are storage indices, not values anyone reads — Option<…> always marks nullability of readable values.

Additionally, arrow allows null entries in the dictionary’s value table itself, so a valid key can point at a null. That (rare) case is Dictionary<K, Option<V>>. Column<Dictionary<K, V>> (no Option anywhere) guarantees the absence of both.

use quiver::{Column, Dictionary, Utf8};

// Building dictionary-encodes the values (can fail on key overflow):
let column = Column::<Dictionary<i32, Utf8>>::try_from_values(["a", "b", "a"]).unwrap();
assert_eq!(column.value(2), "a"); // transparent: reads like a plain column
assert_eq!(column.to_vec(), ["a", "b", "a"]);

This type is never instantiated — it only appears as a type parameter.

Trait Implementations§

Source§

impl<K: DictionaryKey + 'static, V: ConcreteType + 'static> ConcreteType for Dictionary<K, V>

Source§

fn datatype() -> DataType

The exact arrow datatype, built recursively (including the nullability of inner fields).
Source§

fn build( values: impl Iterator<Item = Option<Self::Owned>>, ) -> Result<ArrayRef, ColumnError>

Builds an arrow array of this datatype from owned values. Read more
Source§

impl<K: DictionaryKey + 'static, V: LogicalType + 'static> LogicalType for Dictionary<K, V>

Source§

type Typed = TypedDictionary<K, V>

The fully-downcast, validated representation of one column of this datatype. Cheap to clone (arrow arrays are reference-counted).
Source§

type Value<'a> = <V as LogicalType>::Value<'a>

Zero-copy element view: &'a str for Utf8, i64 for i64, an iterator for List<T>, Option<…> for Option<T>.
Source§

type Owned = <V as LogicalType>::Owned

The owned value of one element, used by the convenience constructors: String for Utf8, Option<i64> for Option<i64>, Vec<…> for List<…>, etc.
Source§

fn downcast(array: &dyn Array) -> Result<Self::Typed, ColumnError>

Validates that array has an acceptable datatype, then recursively downcasts it — checking the nulls of all children along the way. Read more
Source§

fn is_null(typed: &Self::Typed, index: usize) -> bool

Is the value at index null?
Source§

unsafe fn is_null_unchecked(typed: &Self::Typed, index: usize) -> bool

Like is_null, but without the bounds check. Read more
Source§

fn value(typed: &Self::Typed, index: usize) -> Self::Value<'_>

The value at index. Read more
Source§

unsafe fn value_unchecked(typed: &Self::Typed, index: usize) -> Self::Value<'_>

The value at index, without the bounds check value performs. Read more
Source§

fn to_owned_value(value: Self::Value<'_>) -> Self::Owned

Converts a borrowed element value into an owned one, e.g. &strString.
Source§

const NULLABLE: bool = false

May the values at this level be null? (true only for Option<…>)
Source§

impl<K: DictionaryKey + 'static, V: RefType + 'static> RefType for Dictionary<K, V>

References are looked up through the dictionary keys, like LogicalType::value.

Source§

type Ref = <V as RefType>::Ref

The borrow target: str for Utf8, i64 for i64, etc.
Source§

fn value_ref(typed: &Self::Typed, index: usize) -> &Self::Ref

A reference to the value at index. Read more

Auto Trait Implementations§

§

impl<K, V> Freeze for Dictionary<K, V>

§

impl<K, V> RefUnwindSafe for Dictionary<K, V>

§

impl<K, V> Send for Dictionary<K, V>

§

impl<K, V> Sync for Dictionary<K, V>

§

impl<K, V> Unpin for Dictionary<K, V>

§

impl<K, V> UnsafeUnpin for Dictionary<K, V>

§

impl<K, V> UnwindSafe for Dictionary<K, V>

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.