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