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