1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use vortex_error::{vortex_err, VortexResult};
use vortex_scalar::BinaryNumericOperator;

use crate::array::{ConstantArray, ConstantEncoding};
use crate::compute::BinaryNumericFn;
use crate::{ArrayData, ArrayLen as _, IntoArrayData as _};

impl BinaryNumericFn<ConstantArray> for ConstantEncoding {
    fn binary_numeric(
        &self,
        array: &ConstantArray,
        rhs: &ArrayData,
        op: BinaryNumericOperator,
    ) -> VortexResult<Option<ArrayData>> {
        let Some(rhs) = rhs.as_constant() else {
            return Ok(None);
        };

        Ok(Some(
            ConstantArray::new(
                array
                    .scalar()
                    .as_primitive()
                    .checked_numeric_operator(rhs.as_primitive(), op)?
                    .ok_or_else(|| vortex_err!("numeric overflow"))?,
                array.len(),
            )
            .into_array(),
        ))
    }
}