vortex_array/arrays/list/compute/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4mod cast;
5mod filter;
6mod is_constant;
7mod mask;
8mod take;
9
10use vortex_error::VortexResult;
11
12use crate::arrays::{ListArray, ListVTable};
13use crate::compute::{
14    IsSortedKernel, IsSortedKernelAdapter, MinMaxKernel, MinMaxKernelAdapter, MinMaxResult,
15};
16use crate::register_kernel;
17
18impl MinMaxKernel for ListVTable {
19    fn min_max(&self, _array: &ListArray) -> VortexResult<Option<MinMaxResult>> {
20        // TODO(joe): Implement list min max
21        Ok(None)
22    }
23}
24
25register_kernel!(MinMaxKernelAdapter(ListVTable).lift());
26
27// TODO(ngates): Implement is sorted
28impl IsSortedKernel for ListVTable {
29    fn is_sorted(&self, _array: &ListArray) -> VortexResult<Option<bool>> {
30        Ok(None)
31    }
32
33    fn is_strict_sorted(&self, _array: &ListArray) -> VortexResult<Option<bool>> {
34        Ok(None)
35    }
36}
37
38register_kernel!(IsSortedKernelAdapter(ListVTable).lift());
39
40#[cfg(test)]
41mod test {
42    use vortex_buffer::buffer;
43
44    use crate::IntoArray;
45    use crate::arrays::ListArray;
46    use crate::compute::conformance::filter::test_filter_conformance;
47    use crate::compute::conformance::mask::test_mask_conformance;
48    use crate::validity::Validity;
49
50    #[test]
51    fn test_mask_list() {
52        let elements = buffer![0..35].into_array();
53        let offsets = buffer![0, 5, 11, 18, 26, 35].into_array();
54        let validity = Validity::AllValid;
55        let array =
56            ListArray::try_new(elements.into_array(), offsets.into_array(), validity).unwrap();
57
58        test_mask_conformance(array.as_ref());
59    }
60
61    #[test]
62    fn test_filter_list() {
63        let elements = buffer![0..35].into_array();
64        let offsets = buffer![0, 5, 11, 18, 26, 35].into_array();
65        let validity = Validity::AllValid;
66        let array =
67            ListArray::try_new(elements.into_array(), offsets.into_array(), validity).unwrap();
68
69        test_filter_conformance(array.as_ref());
70    }
71}
72
73#[cfg(test)]
74mod tests {
75    use rstest::rstest;
76    use vortex_buffer::buffer;
77
78    use crate::IntoArray;
79    use crate::arrays::{BoolArray, ListArray, PrimitiveArray};
80    use crate::compute::conformance::consistency::test_array_consistency;
81    use crate::validity::Validity;
82
83    #[rstest]
84    // From test_all_consistency
85    #[case::list_simple(ListArray::try_new(
86        buffer![0i32, 1, 2, 3, 4, 5].into_array(),
87        buffer![0, 2, 3, 5, 5, 6].into_array(),
88        Validity::NonNullable,
89    ).unwrap())]
90    #[case::list_nullable(ListArray::try_new(
91        buffer![10i32, 20, 30, 40, 50].into_array(),
92        buffer![0, 2, 3, 4, 5].into_array(),
93        Validity::Array(BoolArray::from_iter(vec![true, false, true, true]).into_array()),
94    ).unwrap())]
95    // Additional test cases
96    #[case::list_empty_lists(ListArray::try_new(
97        buffer![100i32, 200, 300].into_array(),
98        buffer![0, 0, 2, 2, 3, 3].into_array(),
99        Validity::NonNullable,
100    ).unwrap())]
101    #[case::list_single_element(ListArray::try_new(
102        buffer![42i32].into_array(),
103        buffer![0, 1].into_array(),
104        Validity::NonNullable,
105    ).unwrap())]
106    #[case::list_large(ListArray::try_new(
107        buffer![0..1000i32].into_array(),
108        PrimitiveArray::from_iter((0..=100).map(|i| i * 10)).into_array(),
109        Validity::NonNullable,
110    ).unwrap())]
111    fn test_list_consistency(#[case] array: ListArray) {
112        test_array_consistency(array.as_ref());
113    }
114}