vortex_array/arrays/chunked/compute/
mod.rs

1use crate::Array;
2use crate::arrays::ChunkedEncoding;
3use crate::compute::{
4    FillNullFn, IsConstantFn, IsSortedFn, MinMaxFn, ScalarAtFn, SliceFn, TakeFn, UncompressedSizeFn,
5};
6use crate::vtable::ComputeVTable;
7
8mod cast;
9mod compare;
10mod elementwise;
11mod fill_null;
12mod filter;
13mod invert;
14mod is_constant;
15mod is_sorted;
16mod mask;
17mod min_max;
18mod scalar_at;
19mod slice;
20mod sum;
21mod take;
22mod uncompressed_size;
23
24impl ComputeVTable for ChunkedEncoding {
25    fn fill_null_fn(&self) -> Option<&dyn FillNullFn<&dyn Array>> {
26        Some(self)
27    }
28
29    fn is_constant_fn(&self) -> Option<&dyn IsConstantFn<&dyn Array>> {
30        Some(self)
31    }
32
33    fn is_sorted_fn(&self) -> Option<&dyn IsSortedFn<&dyn Array>> {
34        Some(self)
35    }
36
37    fn scalar_at_fn(&self) -> Option<&dyn ScalarAtFn<&dyn Array>> {
38        Some(self)
39    }
40
41    fn slice_fn(&self) -> Option<&dyn SliceFn<&dyn Array>> {
42        Some(self)
43    }
44
45    fn take_fn(&self) -> Option<&dyn TakeFn<&dyn Array>> {
46        Some(self)
47    }
48
49    fn min_max_fn(&self) -> Option<&dyn MinMaxFn<&dyn Array>> {
50        Some(self)
51    }
52
53    fn uncompressed_size_fn(&self) -> Option<&dyn UncompressedSizeFn<&dyn Array>> {
54        Some(self)
55    }
56}
57
58#[cfg(test)]
59mod test {
60    use vortex_buffer::buffer;
61    use vortex_dtype::{DType, Nullability, PType};
62
63    use crate::IntoArray;
64    use crate::array::Array;
65    use crate::arrays::chunked::ChunkedArray;
66    use crate::canonical::ToCanonical;
67    use crate::compute::cast;
68
69    #[test]
70    fn test_cast_chunked() {
71        let arr0 = buffer![0u32, 1].into_array();
72        let arr1 = buffer![2u32, 3].into_array();
73
74        let chunked = ChunkedArray::try_new(
75            vec![arr0, arr1],
76            DType::Primitive(PType::U32, Nullability::NonNullable),
77        )
78        .unwrap()
79        .into_array();
80
81        // Two levels of chunking, just to be fancy.
82        let root = ChunkedArray::try_new(
83            vec![chunked],
84            DType::Primitive(PType::U32, Nullability::NonNullable),
85        )
86        .unwrap()
87        .into_array();
88
89        assert_eq!(
90            cast(
91                &root,
92                &DType::Primitive(PType::U64, Nullability::NonNullable)
93            )
94            .unwrap()
95            .to_primitive()
96            .unwrap()
97            .as_slice::<u64>(),
98            &[0u64, 1, 2, 3],
99        );
100    }
101}