Skip to main content

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::ExecutionCtx;
9use crate::arrays::ConstantArray;
10use crate::arrays::ExtensionArray;
11use crate::arrays::ExtensionVTable;
12use crate::builtins::ArrayBuiltins;
13use crate::scalar_fn::fns::binary::CompareKernel;
14use crate::scalar_fn::fns::operators::CompareOperator;
15use crate::scalar_fn::fns::operators::Operator;
16
17impl CompareKernel for ExtensionVTable {
18    fn compare(
19        lhs: &ExtensionArray,
20        rhs: &dyn Array,
21        operator: CompareOperator,
22        _ctx: &mut ExecutionCtx,
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().to_storage_scalar();
27            return lhs
28                .storage()
29                .to_array()
30                .binary(
31                    ConstantArray::new(storage_scalar, lhs.len()).to_array(),
32                    Operator::from(operator),
33                )
34                .map(Some);
35        }
36
37        // If the RHS is an extension array matching ours, we can extract the storage.
38        if let Some(rhs_ext) = rhs.as_opt::<ExtensionVTable>() {
39            return lhs
40                .storage()
41                .to_array()
42                .binary(rhs_ext.storage().to_array(), Operator::from(operator))
43                .map(Some);
44        }
45
46        // Otherwise, we need the RHS to handle this comparison.
47        Ok(None)
48    }
49}