## 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/primitive.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::bit_iterator::BitSliceIterator;
    19
    use crate::contains_nulls;
    20
    use std::mem::size_of;
    21
    22
    use crate::data::ArrayData;
    23
    24
    use super::utils::equal_len;
    25
    26
    pub(crate) const NULL_SLICES_SELECTIVITY_THRESHOLD: f64 = 0.4;
    27
    28
    1.03k
    pub(super) fn primitive_equal<T>(
    29
    1.03k
        lhs: &ArrayData,
    30
    1.03k
        rhs: &ArrayData,
    31
    1.03k
        lhs_start: usize,
    32
    1.03k
        rhs_start: usize,
    33
    1.03k
        len: usize,
    34
    1.03k
    ) -> bool {
    35
    1.03k
        let byte_width = size_of::<T>();
    36
    1.03k
        let lhs_values = &lhs.buffers()[0].as_slice()[lhs.offset() * byte_width..];
    37
    1.03k
        let rhs_values = &rhs.buffers()[0].as_slice()[rhs.offset() * byte_width..];
    38
    39
        // Only checking one null mask here because by the time the control flow reaches
    40
        // this point, the equality of the two masks would have already been verified.
    41
    1.03k
        if !contains_nulls(lhs.nulls(), lhs_start, len) {
    42
            // without nulls, we just need to compare slices
    43
    348
            equal_len(
    44
    348
                lhs_values,
    45
    348
                rhs_values,
    46
    348
                lhs_start * byte_width,
    47
    348
                rhs_start * byte_width,
    48
    348
                len * byte_width,
    49
            )
    50
        } else {
    51
    683
            let selectivity_frac = lhs.null_count() as f64 / lhs.len() as f64;
    52
    53
    683
            if selectivity_frac >= NULL_SLICES_SELECTIVITY_THRESHOLD {
    54
                // get a ref of the null buffer bytes, to use in testing for nullness
    55
    311
                let lhs_nulls = lhs.nulls().unwrap();
    56
    311
                let rhs_nulls = rhs.nulls().unwrap();
    57
                // with nulls, we need to compare item by item whenever it is not null
    58
    18.8k
                (0..len)311.all311(|i| {
    59
    18.8k
                    let lhs_pos = lhs_start + i;
    60
    18.8k
                    let rhs_pos = rhs_start + i;
    61
    18.8k
                    let lhs_is_null = lhs_nulls.is_null(lhs_pos);
    62
    18.8k
                    let rhs_is_null = rhs_nulls.is_null(rhs_pos);
    63
    64
    18.8k
                    lhs_is_null
    65
    6.35k
                        || (lhs_is_null == rhs_is_null)
    66
    6.35k
                            && equal_len(
    67
    6.35k
                                lhs_values,
    68
    6.35k
                                rhs_values,
    69
    6.35k
                                lhs_pos * byte_width,
    70
    6.35k
                                rhs_pos * byte_width,
    71
    6.35k
                                byte_width, // 1 * byte_width since we are comparing a single entry
    72
                            )
    73
    18.8k
                })
    74
            } else {
    75
    372
                let lhs_nulls = lhs.nulls().unwrap();
    76
    372
                let lhs_slices_iter =
    77
    372
                    BitSliceIterator::new(lhs_nulls.validity(), lhs_start + lhs_nulls.offset(), len);
    78
    372
                let rhs_nulls = rhs.nulls().unwrap();
    79
    372
                let rhs_slices_iter =
    80
    372
                    BitSliceIterator::new(rhs_nulls.validity(), rhs_start + rhs_nulls.offset(), len);
    81
    82
    372
                lhs_slices_iter
    83
    372
                    .zip(rhs_slices_iter)
    84
    16.5k
                    .all372(|((l_start, l_end), (r_start, r_end))| {
    85
    16.5k
                        l_start == r_start
    86
    16.5k
                            && l_end == r_end
    87
    16.5k
                            && equal_len(
    88
    16.5k
                                lhs_values,
    89
    16.5k
                                rhs_values,
    90
    16.5k
                                (lhs_start + l_start) * byte_width,
    91
    16.5k
                                (rhs_start + r_start) * byte_width,
    92
    16.5k
                                (l_end - l_start) * byte_width,
    93
                            )
    94
    16.5k
                    })
    95
            }
    96
        }
    97
    1.03k
    }