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