vortex_array/arrays/constant/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, ConstantVTable};
7use crate::compute::{CompareKernel, CompareKernelAdapter, Operator, scalar_cmp};
8use crate::{Array, ArrayRef, IntoArray, register_kernel};
9
10impl CompareKernel for ConstantVTable {
11    fn compare(
12        &self,
13        lhs: &ConstantArray,
14        rhs: &dyn Array,
15        operator: Operator,
16    ) -> VortexResult<Option<ArrayRef>> {
17        // We only support comparing a constant array to another constant array.
18        // For all other encodings, we assume the constant is on the RHS.
19        if let Some(const_scalar) = rhs.as_constant() {
20            let lhs_scalar = lhs.scalar();
21            let scalar = scalar_cmp(lhs_scalar, &const_scalar, operator);
22            return Ok(Some(ConstantArray::new(scalar, lhs.len()).into_array()));
23        }
24
25        Ok(None)
26    }
27}
28
29register_kernel!(CompareKernelAdapter(ConstantVTable).lift());