Skip to content

Commit 5f1d122

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

File tree

8 files changed

+395
-296
lines changed

8 files changed

+395
-296
lines changed

datafusion/common/src/join_type.rs

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

78113
impl Display for JoinType {

0 commit comments

Comments
 (0)