vortex_array/arrays/constant/compute/
mod.rs1mod binary_numeric;
2mod boolean;
3mod cast;
4mod compare;
5mod filter;
6mod invert;
7mod search_sorted;
8mod sum;
9mod take;
10
11use vortex_error::VortexResult;
12use vortex_scalar::Scalar;
13
14use crate::arrays::ConstantEncoding;
15use crate::arrays::constant::ConstantArray;
16use crate::compute::{ScalarAtFn, SearchSortedFn, SliceFn, TakeFn, UncompressedSizeFn};
17use crate::vtable::ComputeVTable;
18use crate::{Array, ArrayRef};
19
20impl ComputeVTable for ConstantEncoding {
21 fn scalar_at_fn(&self) -> Option<&dyn ScalarAtFn<&dyn Array>> {
22 Some(self)
23 }
24
25 fn search_sorted_fn(&self) -> Option<&dyn SearchSortedFn<&dyn Array>> {
26 Some(self)
27 }
28
29 fn slice_fn(&self) -> Option<&dyn SliceFn<&dyn Array>> {
30 Some(self)
31 }
32
33 fn take_fn(&self) -> Option<&dyn TakeFn<&dyn Array>> {
34 Some(self)
35 }
36
37 fn uncompressed_size_fn(&self) -> Option<&dyn UncompressedSizeFn<&dyn Array>> {
38 Some(self)
39 }
40}
41
42impl ScalarAtFn<&ConstantArray> for ConstantEncoding {
43 fn scalar_at(&self, array: &ConstantArray, _index: usize) -> VortexResult<Scalar> {
44 Ok(array.scalar().clone())
45 }
46}
47
48impl SliceFn<&ConstantArray> for ConstantEncoding {
49 fn slice(&self, array: &ConstantArray, start: usize, stop: usize) -> VortexResult<ArrayRef> {
50 Ok(ConstantArray::new(array.scalar().clone(), stop - start).into_array())
51 }
52}
53
54impl UncompressedSizeFn<&ConstantArray> for ConstantEncoding {
55 fn uncompressed_size(&self, array: &ConstantArray) -> VortexResult<usize> {
56 let scalar = array.scalar();
57
58 let size = match scalar.as_bool_opt() {
59 Some(_) => array.len() / 8,
60 None => array.scalar().nbytes() * array.len(),
61 };
62 Ok(size)
63 }
64}
65
66#[cfg(test)]
67mod test {
68 use vortex_dtype::half::f16;
69 use vortex_scalar::Scalar;
70
71 use super::ConstantArray;
72 use crate::array::Array;
73 use crate::compute::conformance::mask::test_mask;
74
75 #[test]
76 fn test_mask_constant() {
77 test_mask(&ConstantArray::new(Scalar::null_typed::<i32>(), 5).into_array());
78 test_mask(&ConstantArray::new(Scalar::from(3u16), 5).into_array());
79 test_mask(&ConstantArray::new(Scalar::from(1.0f32 / 0.0f32), 5).into_array());
80 test_mask(&ConstantArray::new(Scalar::from(f16::from_f32(3.0f32)), 5).into_array());
81 }
82}