vortex-dict 0.54.0

Vortex dictionary array
Documentation
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors

#[cfg(test)]
mod test {
    use vortex_array::IntoArray as _;
    use vortex_array::arrays::{BoolArray, ListArray, VarBinArray};
    use vortex_array::validity::Validity;
    use vortex_buffer::buffer;

    use crate::DictArray;

    #[test]
    fn test_dict_display() {
        let x = DictArray::try_new(
            buffer![0u8, 0, 0, 1, 0, 3].into_array(),
            VarBinArray::from(vec!["Hello", "你好", "Bonjour", "Hola"]).into_array(),
        )
        .unwrap()
        .into_array();

        assert_eq!(
            x.display_values().to_string(),
            "[\"Hello\", \"Hello\", \"Hello\", \"你好\", \"Hello\", \"Hola\"]"
        )
    }

    #[test]
    fn test_dict_list_dict_display() {
        let elements = DictArray::try_new(
            buffer![0u8, 0, 0, 1, 0, 3, 3, 2].into_array(),
            <VarBinArray as FromIterator<_>>::from_iter([
                Some("Hello"),
                Some("你好"),
                None,
                Some("Bonjour"),
                Some("Hola"),
            ])
            .into_array(),
        )
        .unwrap()
        .into_array();

        assert_eq!(
            elements.display_values().to_string(),
            "[\"Hello\", \"Hello\", \"Hello\", \"你好\", \"Hello\", \"Bonjour\", \"Bonjour\", null]"
        );

        let lists = ListArray::try_new(
            elements,
            buffer![0, 1, 1, 1, 3, 3, 5, 8].into_array(),
            Validity::Array(
                BoolArray::from_iter([true, true, false, true, false, true, true]).into_array(),
            ),
        )
        .unwrap()
        .into_array();

        assert_eq!(
            lists.display_values().to_string(),
            "[[\"Hello\"], [], null, [\"Hello\", \"Hello\"], null, [\"你好\", \"Hello\"], [\"Bonjour\", \"Bonjour\", null]]"
        );

        let x = DictArray::try_new(buffer![6u8, 5, 2, 3, 2, 1].into_array(), lists)
            .unwrap()
            .into_array();

        assert_eq!(
            x.display_values().to_string(),
            "[[\"Bonjour\", \"Bonjour\", null], [\"你好\", \"Hello\"], null, [\"Hello\", \"Hello\"], null, []]"
        )
    }
}