## Coverage Report

#### Created: 2025-11-22 06:00

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

    /Users/andrewlamb/Software/datafusion/datafusion/common/src/types/field.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 arrow::datatypes::{Field, Fields, UnionFields};
    19
    use std::hash::{Hash, Hasher};
    20
    use std::{ops::Deref, sync::Arc};
    21
    22
    use super::{LogicalTypeRef, NativeType};
    23
    24
    /// A record of a logical type, its name and its nullability.
    25
    #[derive(Debug, Clone, Eq, PartialOrd, Ord)]
    26
    pub struct LogicalField {
    27
        pub name: String,
    28
        pub logical_type: LogicalTypeRef,
    29
        pub nullable: bool,
    30
    }
    31
    32
    impl PartialEq for LogicalField {
    33
    0
        fn eq(&self, other: &Self) -> bool {
    34
    0
            self.name == other.name
    35
    0
                && self.logical_type.eq(&other.logical_type)
    36
    0
                && self.nullable == other.nullable
    37
    0
        }
    38
    }
    39
    40
    impl Hash for LogicalField {
    41
    0
        fn hash<H: Hasher>(&self, state: &mut H) {
    42
    0
            self.name.hash(state);
    43
    0
            self.logical_type.hash(state);
    44
    0
            self.nullable.hash(state);
    45
    0
        }
    46
    }
    47
    48
    impl From<&Field> for LogicalField {
    49
    0
        fn from(value: &Field) -> Self {
    50
    0
            Self {
    51
    0
                name: value.name().clone(),
    52
    0
                logical_type: Arc::new(NativeType::from(value.data_type().clone())),
    53
    0
                nullable: value.is_nullable(),
    54
    0
            }
    55
    0
        }
    56
    }
    57
    58
    /// A reference counted [`LogicalField`].
    59
    pub type LogicalFieldRef = Arc<LogicalField>;
    60
    61
    /// A cheaply cloneable, owned collection of [`LogicalFieldRef`].
    62
    #[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
    63
    pub struct LogicalFields(Arc<[LogicalFieldRef]>);
    64
    65
    impl Deref for LogicalFields {
    66
        type Target = [LogicalFieldRef];
    67
    68
    0
        fn deref(&self) -> &Self::Target {
    69
    0
            self.0.as_ref()
    70
    0
        }
    71
    }
    72
    73
    impl From<&Fields> for LogicalFields {
    74
    0
        fn from(value: &Fields) -> Self {
    75
    0
            value
    76
    0
                .iter()
    77
    0
                .map(|field| Arc::new(LogicalField::from(field.as_ref())))
    78
    0
                .collect()
    79
    0
        }
    80
    }
    81
    82
    impl FromIterator<LogicalFieldRef> for LogicalFields {
    83
    0
        fn from_iter<T: IntoIterator<Item = LogicalFieldRef>>(iter: T) -> Self {
    84
    0
            Self(iter.into_iter().collect())
    85
    0
        }
    86
    }
    87
    88
    /// A cheaply cloneable, owned collection of [`LogicalFieldRef`] and their
    89
    /// corresponding type ids.
    90
    #[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
    91
    pub struct LogicalUnionFields(Arc<[(i8, LogicalFieldRef)]>);
    92
    93
    impl Deref for LogicalUnionFields {
    94
        type Target = [(i8, LogicalFieldRef)];
    95
    96
    0
        fn deref(&self) -> &Self::Target {
    97
    0
            self.0.as_ref()
    98
    0
        }
    99
    }
    100
    101
    impl From<&UnionFields> for LogicalUnionFields {
    102
    0
        fn from(value: &UnionFields) -> Self {
    103
    0
            value
    104
    0
                .iter()
    105
    0
                .map(|(i, field)| (i, Arc::new(LogicalField::from(field.as_ref()))))
    106
    0
                .collect()
    107
    0
        }
    108
    }
    109
    110
    impl FromIterator<(i8, LogicalFieldRef)> for LogicalUnionFields {
    111
    0
        fn from_iter<T: IntoIterator<Item = (i8, LogicalFieldRef)>>(iter: T) -> Self {
    112
    0
            Self(iter.into_iter().collect())
    113
    0
        }
    114
    }