Skip to content

Commit e5751d4

Browse files
authored
feat(sqlsmith): Support generate merge into (#13300)
* feat(sqlsmith): Support generate merge into * fix variant display * fix variant display
1 parent 67ee61b commit e5751d4

File tree

13 files changed

+559
-339
lines changed

13 files changed

+559
-339
lines changed

Cargo.lock

Lines changed: 27 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ opendal = { version = "0.41", features = [
116116
] }
117117
ethnum = { version = "1.3.2" }
118118
ordered-float = { version = "3.6.0", default-features = false }
119-
jsonb = { git = "https://github.com/datafuselabs/jsonb", rev = "b29f2ea" }
119+
jsonb = { version = "0.3.0" }
120120

121121
# openraft = { version = "0.8.2", features = ["compat-07"] }
122122
# For debugging

src/query/ast/src/ast/statements/merge_into.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,65 +100,61 @@ pub struct MergeIntoStmt {
100100

101101
impl Display for MergeIntoStmt {
102102
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
103-
write!(f, "MERGE INTO ")?;
103+
write!(f, "MERGE INTO ")?;
104104
write_dot_separated_list(
105105
f,
106106
self.catalog
107107
.iter()
108108
.chain(&self.database)
109109
.chain(Some(&self.table_ident)),
110110
)?;
111-
111+
if let Some(alias) = &self.target_alias {
112+
write!(f, " AS {}", alias.name)?;
113+
}
112114
write!(f, " USING {} ON {}", self.source, self.join_expr)?;
113115

114116
for clause in &self.merge_options {
115117
match clause {
116118
MergeOption::Match(match_clause) => {
117119
write!(f, " WHEN MATCHED ")?;
118120
if let Some(e) = &match_clause.selection {
119-
write!(f, " AND {} ", e)?;
121+
write!(f, "AND {} ", e)?;
120122
}
121-
write!(f, " THEN ")?;
123+
write!(f, "THEN ")?;
122124

123125
match &match_clause.operation {
124126
MatchOperation::Update {
125127
update_list,
126128
is_star,
127129
} => {
128130
if *is_star {
129-
write!(f, " UPDATE * ")?;
131+
write!(f, "UPDATE *")?;
130132
} else {
131-
write!(f, " UPDATE SET ")?;
133+
write!(f, "UPDATE SET ")?;
132134
write_comma_separated_list(f, update_list)?;
133135
}
134136
}
135137
MatchOperation::Delete => {
136-
write!(f, " DELETE ")?;
138+
write!(f, "DELETE")?;
137139
}
138140
}
139141
}
140142
MergeOption::Unmatch(unmatch_clause) => {
141143
write!(f, " WHEN NOT MATCHED ")?;
142144
if let Some(e) = &unmatch_clause.selection {
143-
write!(f, " AND {} ", e)?;
145+
write!(f, "AND {} ", e)?;
144146
}
145-
write!(f, " THEN INSERT ")?;
147+
write!(f, "THEN INSERT")?;
146148
if let Some(columns) = &unmatch_clause.insert_operation.columns {
147149
if !columns.is_empty() {
148150
write!(f, " (")?;
149151
write_comma_separated_list(f, columns)?;
150152
write!(f, ")")?;
151153
}
152154
}
153-
write!(f, "VALUES")?;
154-
for (i, value) in unmatch_clause.insert_operation.values.iter().enumerate() {
155-
if i > 0 {
156-
write!(f, ", ")?;
157-
}
158-
write!(f, "(")?;
159-
write_comma_separated_list(f, vec![value])?;
160-
write!(f, ")")?;
161-
}
155+
write!(f, " VALUES(")?;
156+
write_comma_separated_list(f, unmatch_clause.insert_operation.values.clone())?;
157+
write!(f, ")")?;
162158
}
163159
}
164160
}
@@ -273,7 +269,7 @@ impl Display for MergeSource {
273269
MergeSource::Select {
274270
query,
275271
source_alias,
276-
} => write!(f, "{query} as {source_alias}"),
272+
} => write!(f, "({query}) AS {source_alias}"),
277273
}
278274
}
279275
}

src/query/ast/src/parser/statement.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub fn statement(i: Input) -> IResult<StatementMsg> {
155155

156156
let merge = map(
157157
rule! {
158-
MERGE ~ #hint? ~ INTO ~ #dot_separated_idents_1_to_3 ~ #table_alias? ~ USING
158+
MERGE ~ #hint? ~ INTO ~ #dot_separated_idents_1_to_3 ~ #table_alias? ~ USING
159159
~ #merge_source ~ ON ~ #expr ~ (#match_clause | #unmatch_clause)*
160160
},
161161
|(

0 commit comments

Comments
 (0)