Skip to content

Commit

Permalink
ast: Provide useful info about JoinOperations
Browse files Browse the repository at this point in the history
  • Loading branch information
emk committed Nov 1, 2023
1 parent ac2337b commit 1cc83df
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,42 @@ pub enum JoinOperation {
},
}

impl JoinOperation {
/// The FROM item on the right-hand side of this join.
pub fn from_item(&self) -> &FromItem {
match self {
JoinOperation::ConditionJoin { from_item, .. } => from_item,
JoinOperation::CrossJoin { from_item, .. } => from_item,
}
}

/// Will all columns on the left side of this join become nullable?
pub fn left_nullable(&self) -> bool {
match self {
JoinOperation::ConditionJoin { join_type, .. } => match join_type {
JoinType::Inner { .. } => false,
JoinType::Left { .. } => true,
JoinType::Right { .. } => false,
JoinType::Full { .. } => true,
},
JoinOperation::CrossJoin { .. } => false,
}
}

/// Will all columns on the right side of this join become nullable?
pub fn right_nullable(&self) -> bool {
match self {
JoinOperation::ConditionJoin { join_type, .. } => match join_type {
JoinType::Inner { .. } => false,
JoinType::Left { .. } => false,
JoinType::Right { .. } => true,
JoinType::Full { .. } => true,
},
JoinOperation::CrossJoin { .. } => false,
}
}
}

/// The type of a join.
#[derive(Clone, Debug, Drive, DriveMut, Emit, EmitDefault, Spanned, ToTokens)]
pub enum JoinType {
Expand Down

0 comments on commit 1cc83df

Please sign in to comment.