Skip to main content

vortex_array/arrays/constant/compute/
between.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use vortex_error::VortexResult;
5
6use crate::ArrayRef;
7use crate::IntoArray;
8use crate::arrays::ConstantArray;
9use crate::arrays::ConstantVTable;
10use crate::scalar::Scalar;
11use crate::scalar_fn::fns::between::BetweenOptions;
12use crate::scalar_fn::fns::between::BetweenReduce;
13
14impl BetweenReduce for ConstantVTable {
15    fn between(
16        array: &ConstantArray,
17        lower: &ArrayRef,
18        upper: &ArrayRef,
19        options: &BetweenOptions,
20    ) -> VortexResult<Option<ArrayRef>> {
21        // Can reduce if everything is constant
22        if let Some(((constant, lower), upper)) = array
23            .as_constant()
24            .zip(lower.as_constant())
25            .zip(upper.as_constant())
26        {
27            let BetweenOptions {
28                lower_strict,
29                upper_strict,
30            } = options;
31
32            let lower_result = if lower_strict.is_strict() {
33                lower < constant
34            } else {
35                lower <= constant
36            };
37
38            let upper_result = if upper_strict.is_strict() {
39                constant < upper
40            } else {
41                constant <= upper
42            };
43
44            let result = lower_result && upper_result;
45
46            let scalar = Scalar::bool(
47                result,
48                lower.dtype().nullability() | upper.dtype().nullability(),
49            );
50            return Ok(Some(ConstantArray::new(scalar, array.len()).into_array()));
51        }
52
53        Ok(None)
54    }
55}