## Coverage Report

#### Created: 2025-11-17 14:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)

    /Users/andrewlamb/Software/arrow-rs/arrow-data/src/equal/union.rs

    Line
    Count
    Source
    1
    // Licensed to the Apache Software Foundation (ASF) under one
    2
    // or more contributor license agreements.  See the NOTICE file
    3
    // distributed with this work for additional information
    4
    // regarding copyright ownership.  The ASF licenses this file
    5
    // to you under the Apache License, Version 2.0 (the
    6
    // "License"); you may not use this file except in compliance
    7
    // with the License.  You may obtain a copy of the License at
    8
    //
    9
    //   http://www.apache.org/licenses/LICENSE-2.0
    10
    //
    11
    // Unless required by applicable law or agreed to in writing,
    12
    // software distributed under the License is distributed on an
    13
    // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    14
    // KIND, either express or implied.  See the License for the
    15
    // specific language governing permissions and limitations
    16
    // under the License.
    17
    18
    use crate::data::ArrayData;
    19
    use arrow_schema::{DataType, UnionFields, UnionMode};
    20
    21
    use super::equal_range;
    22
    23
    #[allow(clippy::too_many_arguments)]
    24
    2
    fn equal_dense(
    25
    2
        lhs: &ArrayData,
    26
    2
        rhs: &ArrayData,
    27
    2
        lhs_type_ids: &[i8],
    28
    2
        rhs_type_ids: &[i8],
    29
    2
        lhs_offsets: &[i32],
    30
    2
        rhs_offsets: &[i32],
    31
    2
        lhs_fields: &UnionFields,
    32
    2
        rhs_fields: &UnionFields,
    33
    2
    ) -> bool {
    34
    2
        let offsets = lhs_offsets.iter().zip(rhs_offsets.iter());
    35
    36
    2
        lhs_type_ids
    37
    2
            .iter()
    38
    2
            .zip(rhs_type_ids.iter())
    39
    2
            .zip(offsets)
    40
    6
            .all2(|((l_type_id, r_type_id), (l_offset, r_offset))| {
    41
    6
                let lhs_child_index = lhs_fields
    42
    6
                    .iter()
    43
    7
                    .position6(|(r, _)| r == *l_type_id)
    44
    6
                    .unwrap();
    45
    6
                let rhs_child_index = rhs_fields
    46
    6
                    .iter()
    47
    7
                    .position6(|(r, _)| r == *r_type_id)
    48
    6
                    .unwrap();
    49
    6
                let lhs_values = &lhs.child_data()[lhs_child_index];
    50
    6
                let rhs_values = &rhs.child_data()[rhs_child_index];
    51
    52
    6
                equal_range(
    53
    6
                    lhs_values,
    54
    6
                    rhs_values,
    55
    6
                    *l_offset as usize,
    56
    6
                    *r_offset as usize,
    57
                    1,
    58
                )
    59
    6
            })
    60
    2
    }
    61
    62
    3
    fn equal_sparse(
    63
    3
        lhs: &ArrayData,
    64
    3
        rhs: &ArrayData,
    65
    3
        lhs_start: usize,
    66
    3
        rhs_start: usize,
    67
    3
        len: usize,
    68
    3
    ) -> bool {
    69
    3
        lhs.child_data()
    70
    3
            .iter()
    71
    3
            .zip(rhs.child_data())
    72
    3
            .all(|(lhs_values, rhs_values)| {
    73
    3
                equal_range(
    74
    3
                    lhs_values,
    75
    3
                    rhs_values,
    76
    3
                    lhs_start + lhs.offset(),
    77
    3
                    rhs_start + rhs.offset(),
    78
    3
                    len,
    79
                )
    80
    3
            })
    81
    3
    }
    82
    83
    5
    pub(super) fn union_equal(
    84
    5
        lhs: &ArrayData,
    85
    5
        rhs: &ArrayData,
    86
    5
        lhs_start: usize,
    87
    5
        rhs_start: usize,
    88
    5
        len: usize,
    89
    5
    ) -> bool {
    90
    5
        let lhs_type_ids = lhs.buffer::<i8>(0);
    91
    5
        let rhs_type_ids = rhs.buffer::<i8>(0);
    92
    93
    5
        let lhs_type_id_range = &lhs_type_ids[lhs_start..lhs_start + len];
    94
    5
        let rhs_type_id_range = &rhs_type_ids[rhs_start..rhs_start + len];
    95
    96
    5
        match (lhs.data_type(), rhs.data_type()) {
    97
            (
    98
    2
                DataType::Union(lhs_fields, UnionMode::Dense),
    99
    2
                DataType::Union(rhs_fields, UnionMode::Dense),
    100
            ) => {
    101
    2
                let lhs_offsets = lhs.buffer::<i32>(1);
    102
    2
                let rhs_offsets = rhs.buffer::<i32>(1);
    103
    104
    2
                let lhs_offsets_range = &lhs_offsets[lhs_start..lhs_start + len];
    105
    2
                let rhs_offsets_range = &rhs_offsets[rhs_start..rhs_start + len];
    106
    107
    2
                lhs_type_id_range == rhs_type_id_range
    108
    2
                    && equal_dense(
    109
    2
                        lhs,
    110
    2
                        rhs,
    111
    2
                        lhs_type_id_range,
    112
    2
                        rhs_type_id_range,
    113
    2
                        lhs_offsets_range,
    114
    2
                        rhs_offsets_range,
    115
    2
                        lhs_fields,
    116
    2
                        rhs_fields,
    117
                    )
    118
            }
    119
            (DataType::Union(_, UnionMode::Sparse), DataType::Union(_, UnionMode::Sparse)) => {
    120
    3
                lhs_type_id_range == rhs_type_id_range
    121
    3
                    && equal_sparse(lhs, rhs, lhs_start, rhs_start, len)
    122
            }
    123
    0
            _ => unimplemented!(
    124
                "Logical equality not yet implemented between dense and sparse union arrays"
    125
            ),
    126
        }
    127
    5
    }