## Coverage Report

#### Created: 2024-10-13 08:39

    /Users/andrewlamb/Software/datafusion/datafusion/common/src/join_type.rs

    Line
    Count
    Source (jump to first uncovered line)
    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
    //! Defines the [`JoinType`], [`JoinConstraint`] and [`JoinSide`] types.
    19
    20
    use std::{
    21
        fmt::{self, Display, Formatter},
    22
        str::FromStr,
    23
    };
    24
    25
    use crate::error::_not_impl_err;
    26
    use crate::{DataFusionError, Result};
    27
    28
    /// Join type
    29
    #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Hash)]
    30
    pub enum JoinType {
    31
        /// Inner Join
    32
        Inner,
    33
        /// Left Join
    34
        Left,
    35
        /// Right Join
    36
        Right,
    37
        /// Full Join
    38
        Full,
    39
        /// Left Semi Join
    40
        LeftSemi,
    41
        /// Right Semi Join
    42
        RightSemi,
    43
        /// Left Anti Join
    44
        LeftAnti,
    45
        /// Right Anti Join
    46
        RightAnti,
    47
    }
    48
    49
    impl JoinType {
    50
    0
        pub fn is_outer(self) -> bool {
    51
    0
            self == JoinType::Left || self == JoinType::Right || self == JoinType::Full
    52
    0
        }
    53
    }
    54
    55
    impl Display for JoinType {
    56
    0
        fn fmt(&self, f: &mut Formatter) -> fmt::Result {
    57
    0
            let join_type = match self {
    58
    0
                JoinType::Inner => "Inner",
    59
    0
                JoinType::Left => "Left",
    60
    0
                JoinType::Right => "Right",
    61
    0
                JoinType::Full => "Full",
    62
    0
                JoinType::LeftSemi => "LeftSemi",
    63
    0
                JoinType::RightSemi => "RightSemi",
    64
    0
                JoinType::LeftAnti => "LeftAnti",
    65
    0
                JoinType::RightAnti => "RightAnti",
    66
            };
    67
    0
            write!(f, "{join_type}")
    68
    0
        }
    69
    }
    70
    71
    impl FromStr for JoinType {
    72
        type Err = DataFusionError;
    73
    74
    0
        fn from_str(s: &str) -> Result<Self> {
    75
    0
            let s = s.to_uppercase();
    76
    0
            match s.as_str() {
    77
    0
                "INNER" => Ok(JoinType::Inner),
    78
    0
                "LEFT" => Ok(JoinType::Left),
    79
    0
                "RIGHT" => Ok(JoinType::Right),
    80
    0
                "FULL" => Ok(JoinType::Full),
    81
    0
                "LEFTSEMI" => Ok(JoinType::LeftSemi),
    82
    0
                "RIGHTSEMI" => Ok(JoinType::RightSemi),
    83
    0
                "LEFTANTI" => Ok(JoinType::LeftAnti),
    84
    0
                "RIGHTANTI" => Ok(JoinType::RightAnti),
    85
    0
                _ => _not_impl_err!("The join type {s} does not exist or is not implemented"),
    86
            }
    87
    0
        }
    88
    }
    89
    90
    /// Join constraint
    91
    #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Hash)]
    92
    pub enum JoinConstraint {
    93
        /// Join ON
    94
        On,
    95
        /// Join USING
    96
        Using,
    97
    }
    98
    99
    impl Display for JoinSide {
    100
    0
        fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
    101
    0
            match self {
    102
    0
                JoinSide::Left => write!(f, "left"),
    103
    0
                JoinSide::Right => write!(f, "right"),
    104
            }
    105
    0
        }
    106
    }
    107
    108
    /// Join side.
    109
    /// Stores the referred table side during calculations
    110
    #[derive(Debug, Clone, Copy, PartialEq)]
    111
    pub enum JoinSide {
    112
        /// Left side of the join
    113
        Left,
    114
        /// Right side of the join
    115
        Right,
    116
    }
    117
    118
    impl JoinSide {
    119
        /// Inverse the join side
    120
    6.88k
        pub fn negate(&self) -> Self {
    121
    6.88k
            match self {
    122
    2.94k
                JoinSide::Left => JoinSide::Right,
    123
    3.94k
                JoinSide::Right => JoinSide::Left,
    124
            }
    125
    6.88k
        }
    126
    }