Skip to content

Commit 8e32022

Browse files
committed
Move join type input swapping to pub methods on Joins
1 parent 2d985b4 commit 8e32022

File tree

8 files changed

+397
-287
lines changed

8 files changed

+397
-287
lines changed

datafusion/common/src/join_type.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,40 @@ impl JoinType {
7373
pub fn is_outer(self) -> bool {
7474
self == JoinType::Left || self == JoinType::Right || self == JoinType::Full
7575
}
76+
77+
/// Returns the `JoinType` if the (2) inputs were swapped
78+
///
79+
/// Panics if [`Self::supports_swap`] returns false
80+
pub fn swap(&self) -> JoinType {
81+
match self {
82+
JoinType::Inner => JoinType::Inner,
83+
JoinType::Full => JoinType::Full,
84+
JoinType::Left => JoinType::Right,
85+
JoinType::Right => JoinType::Left,
86+
JoinType::LeftSemi => JoinType::RightSemi,
87+
JoinType::RightSemi => JoinType::LeftSemi,
88+
JoinType::LeftAnti => JoinType::RightAnti,
89+
JoinType::RightAnti => JoinType::LeftAnti,
90+
JoinType::LeftMark => {
91+
unreachable!("LeftMark join type does not support swapping")
92+
}
93+
}
94+
}
95+
96+
/// Does the join type support swapping inputs?
97+
pub fn supports_swap(&self) -> bool {
98+
matches!(
99+
self,
100+
JoinType::Inner
101+
| JoinType::Left
102+
| JoinType::Right
103+
| JoinType::Full
104+
| JoinType::LeftSemi
105+
| JoinType::RightSemi
106+
| JoinType::LeftAnti
107+
| JoinType::RightAnti
108+
)
109+
}
76110
}
77111

78112
impl Display for JoinType {

0 commit comments

Comments
 (0)