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            Ok(Some(
26                DictArray::try_new(array.codes().clone(), values)?.into_array(),
27            ))
28        } else {
29            Ok(None)
30        }
31    }
32}
33
34register_kernel!(LikeKernelAdapter(DictVTable).lift());