vortex_array/arrays/dict/
arrow.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use arrow_array::types::ArrowDictionaryKeyType;
5use arrow_array::{AnyDictionaryArray, DictionaryArray};
6
7use super::DictArray;
8use crate::ArrayRef;
9use crate::arrow::FromArrowArray;
10
11impl<K: ArrowDictionaryKeyType> FromArrowArray<&DictionaryArray<K>> for DictArray {
12    fn from_arrow(array: &DictionaryArray<K>, nullable: bool) -> Self {
13        let keys = AnyDictionaryArray::keys(array);
14        let keys = ArrayRef::from_arrow(keys, keys.is_nullable());
15        let values = ArrayRef::from_arrow(array.values().as_ref(), nullable);
16        // SAFETY: we assume that Arrow has checked the invariants on construction
17        unsafe { DictArray::new_unchecked(keys, values) }
18    }
19}