vortex_array/arrays/decimal/compute/
is_constant.rs

1use itertools::Itertools;
2use vortex_error::VortexResult;
3use vortex_scalar::match_each_decimal_value_type;
4
5use crate::arrays::{DecimalArray, DecimalVTable};
6use crate::compute::{IsConstantKernel, IsConstantKernelAdapter, IsConstantOpts};
7use crate::register_kernel;
8
9impl IsConstantKernel for DecimalVTable {
10    fn is_constant(
11        &self,
12        array: &DecimalArray,
13        _opts: &IsConstantOpts,
14    ) -> VortexResult<Option<bool>> {
15        let constant = match_each_decimal_value_type!(array.values_type, |S| {
16            array.buffer::<S>().iter().all_equal()
17        });
18        Ok(Some(constant))
19    }
20}
21
22register_kernel!(IsConstantKernelAdapter(DecimalVTable).lift());
23
24#[cfg(test)]
25mod tests {
26    use vortex_buffer::buffer;
27    use vortex_dtype::DecimalDType;
28
29    use crate::arrays::DecimalArray;
30    use crate::compute::is_constant;
31    use crate::validity::Validity;
32
33    #[test]
34    fn test_is_constant() {
35        let array = DecimalArray::new(
36            buffer![0i128, 1i128, 2i128],
37            DecimalDType::new(19, 0),
38            Validity::NonNullable,
39        );
40
41        assert!(!is_constant(array.as_ref()).unwrap().unwrap());
42
43        let array = DecimalArray::new(
44            buffer![100i128, 100i128, 100i128],
45            DecimalDType::new(19, 0),
46            Validity::NonNullable,
47        );
48
49        assert!(is_constant(array.as_ref()).unwrap().unwrap());
50    }
51}