vortex_array/vtable/
canonical.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use vortex_error::vortex_panic;
5
6use crate::Canonical;
7use crate::builders::ArrayBuilder;
8use crate::vtable::{NotSupported, VTable};
9
10pub trait CanonicalVTable<V: VTable> {
11    /// Returns the canonical representation of the array.
12    ///
13    /// ## Post-conditions
14    /// - The length is equal to that of the input array.
15    /// - The [`vortex_dtype::DType`] is equal to that of the input array.
16    // TODO(ngates): rename to `decode`
17    fn canonicalize(array: &V::Array) -> Canonical;
18
19    /// Writes the array into a canonical builder.
20    ///
21    /// ## Post-conditions
22    /// - The length of the builder is incremented by the length of the input array.
23    fn append_to_builder(array: &V::Array, builder: &mut dyn ArrayBuilder) {
24        let canonical = Self::canonicalize(array);
25        builder.extend_from_array(canonical.as_ref())
26    }
27}
28
29impl<V: VTable> CanonicalVTable<V> for NotSupported {
30    fn canonicalize(array: &V::Array) -> Canonical {
31        vortex_panic!(
32            "Legacy canonicalize is not supported for {} arrays",
33            array.encoding_id()
34        )
35    }
36}