Skip to content

Commit

Permalink
Move join type input swapping to pub methods on Joins
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Dec 26, 2024
1 parent 2d985b4 commit 8e32022
Show file tree
Hide file tree
Showing 8 changed files with 397 additions and 287 deletions.
34 changes: 34 additions & 0 deletions datafusion/common/src/join_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,40 @@ impl JoinType {
pub fn is_outer(self) -> bool {
self == JoinType::Left || self == JoinType::Right || self == JoinType::Full
}

/// Returns the `JoinType` if the (2) inputs were swapped
///
/// Panics if [`Self::supports_swap`] returns false
pub fn swap(&self) -> JoinType {
match self {
JoinType::Inner => JoinType::Inner,
JoinType::Full => JoinType::Full,
JoinType::Left => JoinType::Right,
JoinType::Right => JoinType::Left,
JoinType::LeftSemi => JoinType::RightSemi,
JoinType::RightSemi => JoinType::LeftSemi,
JoinType::LeftAnti => JoinType::RightAnti,
JoinType::RightAnti => JoinType::LeftAnti,
JoinType::LeftMark => {
unreachable!("LeftMark join type does not support swapping")
}
}
}

/// Does the join type support swapping inputs?
pub fn supports_swap(&self) -> bool {
matches!(
self,
JoinType::Inner
| JoinType::Left
| JoinType::Right
| JoinType::Full
| JoinType::LeftSemi
| JoinType::RightSemi
| JoinType::LeftAnti
| JoinType::RightAnti
)
}
}

impl Display for JoinType {
Expand Down
Loading

0 comments on commit 8e32022

Please sign in to comment.