Skip to main content

vortex_array/arrays/map/compute/
slice.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use std::ops::Range;
5
6use vortex_error::VortexResult;
7
8use crate::ArrayRef;
9use crate::array::ArrayView;
10use crate::arrays::ListView;
11use crate::arrays::map::Map;
12use crate::arrays::map::MapArrayExt;
13use crate::arrays::map::MapArraySlotsExt;
14use crate::arrays::map::compute::rebuild_map_from_array;
15use crate::arrays::slice::SliceKernel;
16use crate::arrays::slice::SliceReduce;
17use crate::executor::ExecutionCtx;
18
19impl SliceReduce for Map {
20    fn slice(array: ArrayView<'_, Self>, range: Range<usize>) -> VortexResult<Option<ArrayRef>> {
21        let Some(sliced_entries) =
22            <ListView as SliceReduce>::slice(array.entries().as_::<ListView>(), range)?
23        else {
24            return Ok(None);
25        };
26
27        rebuild_map_from_array(array.map_dtype().clone(), sliced_entries).map(Some)
28    }
29}
30
31impl SliceKernel for Map {
32    fn slice(
33        array: ArrayView<'_, Self>,
34        range: Range<usize>,
35        _ctx: &mut ExecutionCtx,
36    ) -> VortexResult<Option<ArrayRef>> {
37        <Self as SliceReduce>::slice(array, range)
38    }
39}