vortex_runend/compute/
binary_numeric.rs1use vortex_array::arrays::ConstantArray;
2use vortex_array::compute::{NumericKernel, NumericKernelAdapter, numeric};
3use vortex_array::{Array, ArrayRef, IntoArray, register_kernel};
4use vortex_error::VortexResult;
5use vortex_scalar::NumericOperator;
6
7use crate::{RunEndArray, RunEndVTable};
8
9impl NumericKernel for RunEndVTable {
10 fn numeric(
11 &self,
12 array: &RunEndArray,
13 rhs: &dyn Array,
14 op: NumericOperator,
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 numeric(array.values(), &rhs_const_array, op)?,
26 array.offset(),
27 array.len(),
28 )?
29 .into_array(),
30 ))
31 }
32}
33
34register_kernel!(NumericKernelAdapter(RunEndVTable).lift());
35
36#[cfg(test)]
37mod tests {
38 use vortex_array::IntoArray;
39 use vortex_array::arrays::PrimitiveArray;
40 use vortex_array::compute::conformance::binary_numeric::test_numeric;
41
42 use crate::RunEndArray;
43
44 fn ree_array() -> RunEndArray {
45 RunEndArray::encode(
46 PrimitiveArray::from_iter([1, 1, 1, 4, 4, 4, 2, 2, 5, 5, 5, 5]).into_array(),
47 )
48 .unwrap()
49 }
50
51 #[test]
52 fn test_runend_binary_numeric() {
53 let array = ree_array().into_array();
54 test_numeric::<i32>(array)
55 }
56}