vortex_dict/compute/
like.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use vortex_array::arrays::ConstantArray;
5use vortex_array::compute::{LikeKernel, LikeKernelAdapter, LikeOptions, like};
6use vortex_array::{Array, ArrayRef, IntoArray, register_kernel};
7use vortex_error::VortexResult;
8
9use crate::{DictArray, DictVTable};
10
11impl LikeKernel for DictVTable {
12    fn like(
13        &self,
14        array: &DictArray,
15        pattern: &dyn Array,
16        options: LikeOptions,
17    ) -> VortexResult<Option<ArrayRef>> {
18        // if we have more values than codes, it is faster to canonicalise first.
19        if array.values().len() > array.codes().len() {
20            return Ok(None);
21        }
22        if let Some(pattern) = pattern.as_constant() {
23            let pattern = ConstantArray::new(pattern, array.values().len()).into_array();
24            let values = like(array.values(), &pattern, options)?;
25
26            // SAFETY: LIKE preserves the len of the values, so codes are still pointing at
27            //  valid positions.
28            unsafe {
29                Ok(Some(
30                    DictArray::new_unchecked(array.codes().clone(), values).into_array(),
31                ))
32            }
33        } else {
34            Ok(None)
35        }
36    }
37}
38
39register_kernel!(LikeKernelAdapter(DictVTable).lift());