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