vortex_runend/compute/
binary_numeric.rs1use vortex_array::arrays::ConstantArray;
2use vortex_array::compute::{BinaryNumericFn, binary_numeric};
3use vortex_array::{Array, ArrayRef};
4use vortex_error::VortexResult;
5use vortex_scalar::BinaryNumericOperator;
6
7use crate::{RunEndArray, RunEndEncoding};
8
9impl BinaryNumericFn<&RunEndArray> for RunEndEncoding {
10 fn binary_numeric(
11 &self,
12 array: &RunEndArray,
13 rhs: &dyn Array,
14 op: BinaryNumericOperator,
15 ) -> VortexResult<Option<ArrayRef>> {
16 let Some(rhs_scalar) = rhs.as_constant() else {
17 return Ok(None);
18 };
19
20 let rhs_const_array = ConstantArray::new(rhs_scalar, array.values().len()).into_array();
21
22 Ok(Some(
23 RunEndArray::with_offset_and_length(
24 array.ends().clone(),
25 binary_numeric(array.values(), &rhs_const_array, op)?,
26 array.offset(),
27 array.len(),
28 )?
29 .into_array(),
30 ))
31 }
32}
33
34#[cfg(test)]
35mod tests {
36 use vortex_array::Array;
37 use vortex_array::arrays::PrimitiveArray;
38 use vortex_array::compute::conformance::binary_numeric::test_binary_numeric;
39
40 use crate::RunEndArray;
41
42 fn ree_array() -> RunEndArray {
43 RunEndArray::encode(
44 PrimitiveArray::from_iter([1, 1, 1, 4, 4, 4, 2, 2, 5, 5, 5, 5]).into_array(),
45 )
46 .unwrap()
47 }
48
49 #[test]
50 fn test_runend_binary_numeric() {
51 let array = ree_array().into_array();
52 test_binary_numeric::<i32>(array)
53 }
54}