Skip to main content

vortex_array/arrays/null/compute/
take.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::ArrayRef;
8use crate::ExecutionCtx;
9use crate::IntoArray;
10use crate::array::ArrayView;
11use crate::arrays::Null;
12use crate::arrays::NullArray;
13use crate::arrays::PrimitiveArray;
14use crate::arrays::dict::TakeExecute;
15use crate::match_each_integer_ptype;
16
17impl TakeExecute for Null {
18    #[expect(clippy::cast_possible_truncation)]
19    fn take(
20        array: ArrayView<'_, Null>,
21        indices: &ArrayRef,
22        ctx: &mut ExecutionCtx,
23    ) -> VortexResult<Option<ArrayRef>> {
24        let indices = indices.clone().execute::<PrimitiveArray>(ctx)?;
25
26        // Enforce all indices are valid
27        match_each_integer_ptype!(indices.ptype(), |T| {
28            for index in indices.as_slice::<T>() {
29                if (*index as usize) >= array.len() {
30                    vortex_bail!(
31                        "index {} out of bounds from {} to {}",
32                        *index as usize,
33                        0,
34                        array.len()
35                    );
36                }
37            }
38        });
39
40        Ok(Some(NullArray::new(indices.len()).into_array()))
41    }
42}