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): why do we report the wrong thing?
28impl IsSortedKernel for ListVTable {
29    fn is_sorted(&self, _array: &ListArray) -> VortexResult<bool> {
30        Ok(false)
31    }
32
33    fn is_strict_sorted(&self, _array: &ListArray) -> VortexResult<bool> {
34        Ok(false)
35    }
36}
37
38register_kernel!(IsSortedKernelAdapter(ListVTable).lift());
39
40#[cfg(test)]
41mod test {
42    use crate::IntoArray;
43    use crate::arrays::{ListArray, PrimitiveArray};
44    use crate::compute::conformance::filter::test_filter_conformance;
45    use crate::compute::conformance::mask::test_mask_conformance;
46    use crate::validity::Validity;
47
48    #[test]
49    fn test_mask_list() {
50        let elements = PrimitiveArray::from_iter(0..35);
51        let offsets = PrimitiveArray::from_iter([0, 5, 11, 18, 26, 35]);
52        let validity = Validity::AllValid;
53        let array =
54            ListArray::try_new(elements.into_array(), offsets.into_array(), validity).unwrap();
55
56        test_mask_conformance(array.as_ref());
57    }
58
59    #[test]
60    fn test_filter_list() {
61        let elements = PrimitiveArray::from_iter(0..35);
62        let offsets = PrimitiveArray::from_iter([0, 5, 11, 18, 26, 35]);
63        let validity = Validity::AllValid;
64        let array =
65            ListArray::try_new(elements.into_array(), offsets.into_array(), validity).unwrap();
66
67        test_filter_conformance(array.as_ref());
68    }
69}
70
71#[cfg(test)]
72mod tests {
73    use rstest::rstest;
74
75    use crate::IntoArray;
76    use crate::arrays::{BoolArray, ListArray, PrimitiveArray};
77    use crate::compute::conformance::consistency::test_array_consistency;
78    use crate::validity::Validity;
79
80    #[rstest]
81    // From test_all_consistency
82    #[case::list_simple(ListArray::try_new(
83        PrimitiveArray::from_iter([0i32, 1, 2, 3, 4, 5]).into_array(),
84        PrimitiveArray::from_iter([0, 2, 3, 5, 5, 6]).into_array(),
85        Validity::NonNullable,
86    ).unwrap())]
87    #[case::list_nullable(ListArray::try_new(
88        PrimitiveArray::from_iter([10i32, 20, 30, 40, 50]).into_array(),
89        PrimitiveArray::from_iter([0, 2, 3, 4, 5]).into_array(),
90        Validity::Array(BoolArray::from_iter(vec![true, false, true, true]).into_array()),
91    ).unwrap())]
92    // Additional test cases
93    #[case::list_empty_lists(ListArray::try_new(
94        PrimitiveArray::from_iter([100i32, 200, 300]).into_array(),
95        PrimitiveArray::from_iter([0, 0, 2, 2, 3, 3]).into_array(),
96        Validity::NonNullable,
97    ).unwrap())]
98    #[case::list_single_element(ListArray::try_new(
99        PrimitiveArray::from_iter([42i32]).into_array(),
100        PrimitiveArray::from_iter([0, 1]).into_array(),
101        Validity::NonNullable,
102    ).unwrap())]
103    #[case::list_large(ListArray::try_new(
104        PrimitiveArray::from_iter(0..1000i32).into_array(),
105        PrimitiveArray::from_iter((0..=100).map(|i| i * 10)).into_array(),
106        Validity::NonNullable,
107    ).unwrap())]
108    fn test_list_consistency(#[case] array: ListArray) {
109        test_array_consistency(array.as_ref());
110    }
111}