vortex_array/arrays/extension/compute/
compare.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use vortex_error::VortexResult;
5
6use crate::Array;
7use crate::ArrayRef;
8use crate::arrays::ConstantArray;
9use crate::arrays::ExtensionArray;
10use crate::arrays::ExtensionVTable;
11use crate::compute::CompareKernel;
12use crate::compute::CompareKernelAdapter;
13use crate::compute::Operator;
14use crate::compute::{self};
15use crate::register_kernel;
16
17impl CompareKernel for ExtensionVTable {
18    fn compare(
19        &self,
20        lhs: &ExtensionArray,
21        rhs: &dyn Array,
22        operator: Operator,
23    ) -> VortexResult<Option<ArrayRef>> {
24        // If the RHS is a constant, we can extract the storage scalar.
25        if let Some(const_ext) = rhs.as_constant() {
26            let storage_scalar = const_ext.as_extension().storage();
27            return compute::compare(
28                lhs.storage(),
29                ConstantArray::new(storage_scalar, lhs.len()).as_ref(),
30                operator,
31            )
32            .map(Some);
33        }
34
35        // If the RHS is an extension array matching ours, we can extract the storage.
36        if let Some(rhs_ext) = rhs.as_opt::<ExtensionVTable>() {
37            return compute::compare(lhs.storage(), rhs_ext.storage(), operator).map(Some);
38        }
39
40        // Otherwise, we need the RHS to handle this comparison.
41        Ok(None)
42    }
43}
44
45register_kernel!(CompareKernelAdapter(ExtensionVTable).lift());