1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use crate::array::{Array, StructArray};

pub(super) fn equal(lhs: &StructArray, rhs: &StructArray) -> bool {
    lhs.data_type() == rhs.data_type()
        && lhs.len() == rhs.len()
        && match (lhs.validity(), rhs.validity()) {
            (None, None) => lhs.values().iter().eq(rhs.values().iter()),
            (Some(l_validity), Some(r_validity)) => lhs
                .values()
                .iter()
                .zip(rhs.values().iter())
                .all(|(lhs, rhs)| {
                    l_validity.iter().zip(r_validity.iter()).enumerate().all(
                        |(i, (lhs_is_valid, rhs_is_valid))| {
                            if lhs_is_valid && rhs_is_valid {
                                lhs.sliced(i, 1) == rhs.sliced(i, 1)
                            } else {
                                lhs_is_valid == rhs_is_valid
                            }
                        },
                    )
                }),
            (Some(l_validity), None) => {
                lhs.values()
                    .iter()
                    .zip(rhs.values().iter())
                    .all(|(lhs, rhs)| {
                        l_validity.iter().enumerate().all(|(i, lhs_is_valid)| {
                            if lhs_is_valid {
                                lhs.sliced(i, 1) == rhs.sliced(i, 1)
                            } else {
                                // rhs is always valid => different
                                false
                            }
                        })
                    })
            }
            (None, Some(r_validity)) => {
                lhs.values()
                    .iter()
                    .zip(rhs.values().iter())
                    .all(|(lhs, rhs)| {
                        r_validity.iter().enumerate().all(|(i, rhs_is_valid)| {
                            if rhs_is_valid {
                                lhs.sliced(i, 1) == rhs.sliced(i, 1)
                            } else {
                                // lhs is always valid => different
                                false
                            }
                        })
                    })
            }
        }
}