-
Notifications
You must be signed in to change notification settings - Fork 713
Databricks: Add support for UPDATE SET * and INSERT * in MERGE statements
#2325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,11 +18,12 @@ use alloc::{boxed::Box, format, vec, vec::Vec}; | |
| use crate::{ | ||
| ast::{ | ||
| Merge, MergeAction, MergeClause, MergeClauseKind, MergeInsertExpr, MergeInsertKind, | ||
| MergeUpdateExpr, ObjectName, OutputClause, SetExpr, | ||
| MergeUpdateExpr, MergeUpdateKind, ObjectName, OutputClause, SetExpr, | ||
| }, | ||
| dialect::{BigQueryDialect, GenericDialect, MySqlDialect}, | ||
| keywords::Keyword, | ||
| parser::IsOptional, | ||
| tokenizer::Token, | ||
| tokenizer::TokenWithSpan, | ||
| }; | ||
|
|
||
|
|
@@ -120,7 +121,13 @@ impl Parser<'_> { | |
|
|
||
| let update_token = self.get_current_token().clone(); | ||
| self.expect_keyword_is(Keyword::SET)?; | ||
| let assignments = self.parse_comma_separated(Parser::parse_assignment)?; | ||
| let kind = if self.dialect.supports_merge_star_syntax() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looks like we should be able to drop the dialect method and let the parser accept the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
done |
||
| && self.consume_token(&Token::Mul) | ||
| { | ||
| MergeUpdateKind::Star | ||
| } else { | ||
| MergeUpdateKind::Set(self.parse_comma_separated(Parser::parse_assignment)?) | ||
| }; | ||
| let update_predicate = if self.parse_keyword(Keyword::WHERE) { | ||
| Some(self.parse_expr()?) | ||
| } else { | ||
|
|
@@ -134,7 +141,7 @@ impl Parser<'_> { | |
| }; | ||
| MergeAction::Update(MergeUpdateExpr { | ||
| update_token: update_token.into(), | ||
| assignments, | ||
| kind, | ||
| update_predicate, | ||
| delete_predicate, | ||
| }) | ||
|
|
@@ -167,32 +174,44 @@ impl Parser<'_> { | |
| }; | ||
|
|
||
| let insert_token = self.get_current_token().clone(); | ||
| let is_mysql = dialect_of!(self is MySqlDialect); | ||
|
|
||
| let columns = self.parse_merge_clause_insert_columns(is_mysql)?; | ||
| let (kind, kind_token) = if dialect_of!(self is BigQueryDialect | GenericDialect) | ||
| && self.parse_keyword(Keyword::ROW) | ||
| if self.dialect.supports_merge_star_syntax() && self.consume_token(&Token::Mul) | ||
| { | ||
| (MergeInsertKind::Row, self.get_current_token().clone()) | ||
| } else { | ||
| self.expect_keyword_is(Keyword::VALUES)?; | ||
| let values_token = self.get_current_token().clone(); | ||
| let values = self.parse_values(is_mysql, false)?; | ||
| (MergeInsertKind::Values(values), values_token) | ||
| }; | ||
| let insert_predicate = if self.parse_keyword(Keyword::WHERE) { | ||
| Some(self.parse_expr()?) | ||
| let star_token = self.get_current_token().clone(); | ||
| MergeAction::Insert(MergeInsertExpr { | ||
| insert_token: insert_token.into(), | ||
| columns: vec![], | ||
| kind_token: star_token.into(), | ||
| kind: MergeInsertKind::Star, | ||
| insert_predicate: None, | ||
| }) | ||
| } else { | ||
| None | ||
| }; | ||
| let is_mysql = dialect_of!(self is MySqlDialect); | ||
| let columns = self.parse_merge_clause_insert_columns(is_mysql)?; | ||
| let (kind, kind_token) = if dialect_of!(self is BigQueryDialect | GenericDialect) | ||
| && self.parse_keyword(Keyword::ROW) | ||
| { | ||
| (MergeInsertKind::Row, self.get_current_token().clone()) | ||
| } else { | ||
| self.expect_keyword_is(Keyword::VALUES)?; | ||
| let values_token = self.get_current_token().clone(); | ||
| let values = self.parse_values(is_mysql, false)?; | ||
| (MergeInsertKind::Values(values), values_token) | ||
| }; | ||
| let insert_predicate = if self.parse_keyword(Keyword::WHERE) { | ||
| Some(self.parse_expr()?) | ||
| } else { | ||
| None | ||
| }; | ||
|
|
||
| MergeAction::Insert(MergeInsertExpr { | ||
| insert_token: insert_token.into(), | ||
| columns, | ||
| kind_token: kind_token.into(), | ||
| kind, | ||
| insert_predicate, | ||
| }) | ||
| MergeAction::Insert(MergeInsertExpr { | ||
| insert_token: insert_token.into(), | ||
| columns, | ||
| kind_token: kind_token.into(), | ||
| kind, | ||
| insert_predicate, | ||
| }) | ||
| } | ||
| } | ||
| _ => { | ||
| return parser_err!( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.