vortex_array/vtable/
operations.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use std::ops::Range;
5
6use vortex_error::vortex_panic;
7use vortex_scalar::Scalar;
8
9use crate::ArrayRef;
10use crate::vtable::{NotSupported, VTable};
11
12pub trait OperationsVTable<V: VTable> {
13    /// Perform a constant-time slice of the array.
14    ///
15    /// If an encoding cannot perform this slice in constant time, it should internally
16    /// store an offset and length in order to defer slicing until the array is accessed.
17    ///
18    /// This function returns [`ArrayRef`] since some encodings can return a simpler array for
19    /// some slices, for example a [`crate::arrays::ChunkedArray`] may slice into a single chunk.
20    ///
21    /// ## Preconditions
22    ///
23    /// Bounds-checking has already been performed by the time this function is called.
24    fn slice(array: &V::Array, range: Range<usize>) -> ArrayRef;
25
26    /// Fetch the scalar at the given index.
27    ///
28    /// ## Preconditions
29    ///
30    /// Bounds-checking has already been performed by the time this function is called,
31    /// and the index is guaranteed to be non-null.
32    fn scalar_at(array: &V::Array, index: usize) -> Scalar;
33}
34
35impl<V: VTable> OperationsVTable<V> for NotSupported {
36    fn slice(array: &V::Array, _range: Range<usize>) -> ArrayRef {
37        vortex_panic!(
38            "Legacy slice operation is not supported for {} arrays",
39            array.encoding_id()
40        )
41    }
42
43    fn scalar_at(array: &V::Array, _index: usize) -> Scalar {
44        vortex_panic!(
45            "Legacy scalar_at operation is not supported for {} arrays",
46            array.encoding_id()
47        )
48    }
49}