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