Skip to main content

vortex_array/arrays/widen/compute/
take.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use vortex_error::VortexResult;
5
6use crate::ArrayRef;
7use crate::Columnar;
8use crate::ExecutionCtx;
9use crate::IntoArray;
10use crate::array::ArrayView;
11use crate::arrays::Widen;
12use crate::arrays::dict::TakeExecute;
13use crate::arrays::widen::WidenArraySlotsExt;
14use crate::arrays::widen::compute::wrap_values;
15
16impl TakeExecute for Widen {
17    fn take(
18        array: ArrayView<'_, Self>,
19        indices: &ArrayRef,
20        ctx: &mut ExecutionCtx,
21    ) -> VortexResult<Option<ArrayRef>> {
22        // Execute the gather, so that no lazy `Dict` sits under the `Widen` (see the `widen`
23        // module docs). `Columnar` keeps a constant gather constant.
24        let values = array
25            .values()
26            .take(indices.clone())?
27            .execute::<Columnar>(ctx)?
28            .into_array();
29        let dtype = array.dtype().with_nullability(values.dtype().nullability());
30
31        wrap_values(values, dtype).map(Some)
32    }
33}