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