vortex_array/array/vtable/operations.rs
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use vortex_error::VortexResult;
5use vortex_error::vortex_bail;
6
7use crate::ExecutionCtx;
8use crate::array::ArrayView;
9use crate::array::VTable;
10use crate::scalar::Scalar;
11use crate::vtable::NotSupported;
12
13/// Element-level operations for an array encoding.
14///
15/// This trait is separated from [`VTable`] so encodings can organize scalar
16/// access independently from traversal, serialization, and execution. The erased
17/// [`ArrayRef`](crate::ArrayRef)
18/// methods perform common checks before dispatching here.
19pub trait OperationsVTable<V: VTable> {
20 /// Fetch the scalar at the given index.
21 ///
22 /// ## Preconditions
23 ///
24 /// Bounds-checking has already been performed by the time this function is called,
25 /// and the index is guaranteed to be non-null. Implementations may assume `index < len`.
26 ///
27 /// ## Postconditions
28 ///
29 /// The returned [`Scalar`] must have the same logical dtype as the array's element dtype.
30 fn scalar_at(
31 array: ArrayView<'_, V>,
32 index: usize,
33 ctx: &mut ExecutionCtx,
34 ) -> VortexResult<Scalar>;
35}
36
37impl<V: VTable> OperationsVTable<V> for NotSupported {
38 fn scalar_at(
39 array: ArrayView<'_, V>,
40 _index: usize,
41 _ctx: &mut ExecutionCtx,
42 ) -> VortexResult<Scalar> {
43 vortex_bail!(
44 "Legacy scalar_at operation is not supported for {} arrays",
45 array.encoding_id()
46 )
47 }
48}