Skip to content

Commit 5cfb01f

Browse files
xitepayman-sigma
authored andcommitted
impl Spanned for MERGE statements (apache#2100)
1 parent 54505c4 commit 5cfb01f

File tree

5 files changed

+418
-47
lines changed

5 files changed

+418
-47
lines changed

src/ast/mod.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4098,6 +4098,8 @@ pub enum Statement {
40984098
/// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/dml-syntax#merge_statement)
40994099
/// [MSSQL](https://learn.microsoft.com/en-us/sql/t-sql/statements/merge-transact-sql?view=sql-server-ver16)
41004100
Merge {
4101+
/// The `MERGE` token that starts the statement.
4102+
merge_token: AttachedToken,
41014103
/// optional INTO keyword
41024104
into: bool,
41034105
/// Specifies the table to merge
@@ -4122,7 +4124,6 @@ pub enum Statement {
41224124
/// Table flag
41234125
table_flag: Option<ObjectName>,
41244126
/// Table name
4125-
41264127
#[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
41274128
table_name: ObjectName,
41284129
has_as: bool,
@@ -5522,6 +5523,7 @@ impl fmt::Display for Statement {
55225523
write!(f, "RELEASE SAVEPOINT {name}")
55235524
}
55245525
Statement::Merge {
5526+
merge_token: _,
55255527
into,
55265528
table,
55275529
source,
@@ -8654,6 +8656,8 @@ impl Display for MergeInsertKind {
86548656
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
86558657
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
86568658
pub struct MergeInsertExpr {
8659+
/// The `INSERT` token that starts the sub-expression.
8660+
pub insert_token: AttachedToken,
86578661
/// Columns (if any) specified by the insert.
86588662
///
86598663
/// Example:
@@ -8662,6 +8666,8 @@ pub struct MergeInsertExpr {
86628666
/// INSERT (product, quantity) ROW
86638667
/// ```
86648668
pub columns: Vec<Ident>,
8669+
/// The token, `[VALUES | ROW]` starting `kind`.
8670+
pub kind_token: AttachedToken,
86658671
/// The insert type used by the statement.
86668672
pub kind: MergeInsertKind,
86678673
}
@@ -8701,9 +8707,16 @@ pub enum MergeAction {
87018707
/// ```sql
87028708
/// UPDATE SET quantity = T.quantity + S.quantity
87038709
/// ```
8704-
Update { assignments: Vec<Assignment> },
8710+
Update {
8711+
/// The `UPDATE` token that starts the sub-expression.
8712+
update_token: AttachedToken,
8713+
assignments: Vec<Assignment>,
8714+
},
87058715
/// A plain `DELETE` clause
8706-
Delete,
8716+
Delete {
8717+
/// The `DELETE` token that starts the sub-expression.
8718+
delete_token: AttachedToken,
8719+
},
87078720
}
87088721

87098722
impl Display for MergeAction {
@@ -8712,10 +8725,10 @@ impl Display for MergeAction {
87128725
MergeAction::Insert(insert) => {
87138726
write!(f, "INSERT {insert}")
87148727
}
8715-
MergeAction::Update { assignments } => {
8728+
MergeAction::Update { assignments, .. } => {
87168729
write!(f, "UPDATE SET {}", display_comma_separated(assignments))
87178730
}
8718-
MergeAction::Delete => {
8731+
MergeAction::Delete { .. } => {
87198732
write!(f, "DELETE")
87208733
}
87218734
}
@@ -8734,6 +8747,8 @@ impl Display for MergeAction {
87348747
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
87358748
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
87368749
pub struct MergeClause {
8750+
/// The `WHEN` token that starts the sub-expression.
8751+
pub when_token: AttachedToken,
87378752
pub clause_kind: MergeClauseKind,
87388753
pub predicate: Option<Expr>,
87398754
pub action: MergeAction,
@@ -8742,6 +8757,7 @@ pub struct MergeClause {
87428757
impl Display for MergeClause {
87438758
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
87448759
let MergeClause {
8760+
when_token: _,
87458761
clause_kind,
87468762
predicate,
87478763
action,
@@ -8765,10 +8781,12 @@ impl Display for MergeClause {
87658781
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
87668782
pub enum OutputClause {
87678783
Output {
8784+
output_token: AttachedToken,
87688785
select_items: Vec<SelectItem>,
87698786
into_table: Option<SelectInto>,
87708787
},
87718788
Returning {
8789+
returning_token: AttachedToken,
87728790
select_items: Vec<SelectItem>,
87738791
},
87748792
}
@@ -8777,6 +8795,7 @@ impl fmt::Display for OutputClause {
87778795
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
87788796
match self {
87798797
OutputClause::Output {
8798+
output_token: _,
87808799
select_items,
87818800
into_table,
87828801
} => {
@@ -8788,7 +8807,10 @@ impl fmt::Display for OutputClause {
87888807
}
87898808
Ok(())
87908809
}
8791-
OutputClause::Returning { select_items } => {
8810+
OutputClause::Returning {
8811+
returning_token: _,
8812+
select_items,
8813+
} => {
87928814
f.write_str("RETURNING ")?;
87938815
display_comma_separated(select_items).fmt(f)
87948816
}

0 commit comments

Comments
 (0)