Skip to main content

vortex_array/arrays/map/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_err;
6
7use crate::ExecutionCtx;
8use crate::array::ArrayView;
9use crate::array::OperationsVTable;
10use crate::array::ProbeState;
11use crate::arrays::Map;
12use crate::arrays::map::MapSlots;
13use crate::scalar::Scalar;
14
15impl OperationsVTable<Map> for Map {
16    type ProbeState = ();
17
18    fn probe_scalar(
19        state: &mut ProbeState<'_, Map>,
20        index: usize,
21        ctx: &mut ExecutionCtx,
22    ) -> VortexResult<Scalar> {
23        let dtype = state.array().dtype().clone();
24        let (_, entries) = state
25            .slot(MapSlots::ENTRIES)?
26            .ok_or_else(|| vortex_err!("Map entries slot is missing"))?
27            .execute_scalar(index, ctx)?
28            .into_parts();
29        // The validated ListView child and Map scalar share the same entry tuple layout.
30        Scalar::try_new(dtype, entries)
31    }
32
33    fn scalar_at(
34        array: ArrayView<'_, Map>,
35        index: usize,
36        ctx: &mut ExecutionCtx,
37    ) -> VortexResult<Scalar> {
38        Self::probe_scalar(&mut ProbeState::once(array), index, ctx)
39    }
40}