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::IntoArray;
9#[expect(deprecated)]
10use crate::ToCanonical as _;
11use crate::array::ArrayView;
12use crate::arrays::Null;
13use crate::arrays::NullArray;
14use crate::arrays::dict::TakeReduce;
15use crate::arrays::dict::TakeReduceAdaptor;
16use crate::match_each_integer_ptype;
17use crate::optimizer::rules::ParentRuleSet;
18
19impl TakeReduce for Null {
20    #[expect(clippy::cast_possible_truncation)]
21    fn take(array: ArrayView<'_, Null>, indices: &ArrayRef) -> VortexResult<Option<ArrayRef>> {
22        #[expect(deprecated)]
23        let indices = indices.to_primitive();
24
25        // Enforce all indices are valid
26        match_each_integer_ptype!(indices.ptype(), |T| {
27            for index in indices.as_slice::<T>() {
28                if (*index as usize) >= array.len() {
29                    vortex_bail!(OutOfBounds: *index as usize, 0, array.len());
30                }
31            }
32        });
33
34        Ok(Some(NullArray::new(indices.len()).into_array()))
35    }
36}
37
38impl Null {
39    pub const TAKE_RULES: ParentRuleSet<Self> =
40        ParentRuleSet::new(&[ParentRuleSet::lift(&TakeReduceAdaptor::<Self>(Self))]);
41}