-
Notifications
You must be signed in to change notification settings - Fork 664
ClickHouse: support alter table update ...
#1476
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 all 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 |
---|---|---|
|
@@ -1081,7 +1081,7 @@ impl<'a> Parser<'a> { | |
self.parse_bigquery_struct_literal() | ||
} | ||
Keyword::PRIOR if matches!(self.state, ParserState::ConnectBy) => { | ||
let expr = self.parse_subexpr(self.dialect.prec_value(Precedence::PlusMinus))?; | ||
let expr = self.parse_subexpr(self.dialect.prec_value(Precedence::Pipe))?; | ||
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. Oh was there a reason for this change? |
||
Ok(Expr::Prior(Box::new(expr))) | ||
} | ||
Keyword::MAP if self.peek_token() == Token::LBrace && self.dialect.support_map_literal_syntax() => { | ||
|
@@ -7156,6 +7156,35 @@ impl<'a> Parser<'a> { | |
partition, | ||
with_name, | ||
} | ||
} else if self.dialect.supports_alter_table_update() && self.parse_keyword(Keyword::UPDATE) | ||
{ | ||
let mut assignments = vec![]; | ||
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. One minor request, could we move this new block to its own function to keep the branch of the current function smaller/more-focused? |
||
loop { | ||
let target = self.parse_assignment_target()?; | ||
self.expect_token(&Token::Eq)?; | ||
// NOTE: Maybe it's better to save the index before parse_subexpr to do a real look | ||
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. Ah so regarding the earlier comment, I think what we could do would be to make pub fn parse_assignment(&mut self) -> Result<Assignment, ParserError> {
self.parse_assignment_with_prec(self.dialect.prec_unknown())
}
fn parse_assignment_with_precedence(self, precedence: u8) -> Result<Assignment, ParserError> {
let target = self.parse_assignment_target()?;
self.expect_token(&Token::Eq)?;
let value = self.parse_subexpr(precedence)?;
Ok(Assignment { target, value })
} That would make it possible to use |
||
// ahead. | ||
let value = self.parse_subexpr(self.dialect.prec_value(Precedence::Between))?; | ||
assignments.push(Assignment { target, value }); | ||
if self.is_parse_comma_separated_end() { | ||
break; | ||
} | ||
} | ||
let partition_id = if self.parse_keywords(&[Keyword::IN, Keyword::PARTITION]) { | ||
Some(self.parse_identifier(false)?) | ||
} else { | ||
None | ||
}; | ||
let selection = if self.parse_keyword(Keyword::WHERE) { | ||
Some(self.parse_expr()?) | ||
} else { | ||
None | ||
}; | ||
AlterTableOperation::Update { | ||
assignments, | ||
partition_id, | ||
selection, | ||
} | ||
} else { | ||
let options: Vec<SqlOption> = | ||
self.parse_options_with_keywords(&[Keyword::SET, Keyword::TBLPROPERTIES])?; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11432,3 +11432,24 @@ fn test_any_some_all_comparison() { | |
verified_stmt("SELECT c1 FROM tbl WHERE c1 <> SOME(SELECT c2 FROM tbl)"); | ||
verified_stmt("SELECT 1 = ANY(WITH x AS (SELECT 1) SELECT * FROM x)"); | ||
} | ||
|
||
#[test] | ||
fn test_parse_alter_table_update() { | ||
let dialects = all_dialects_where(|d| d.supports_alter_table_update()); | ||
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. Since the change introduces a new node in the AST, one style of test I think could be useful is to assert the returned AST that it matches what we expect. i.e a test in this style for alter_policy 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. OK, I'll add it later. |
||
let cases = [ | ||
( | ||
"ALTER TABLE t UPDATE col1 = 1, col2 = col3 + col4 WHERE cod4 = 1", | ||
true, | ||
), | ||
("ALTER TABLE t UPDATE c = 0 IN PARTITION abc", true), | ||
("ALTER TABLE t UPDATE", false), | ||
("ALTER TABLE t UPDATE c WHERE 1 = 1", false), | ||
]; | ||
for (sql, is_valid) in cases { | ||
if is_valid { | ||
dialects.verified_stmt(sql); | ||
} else { | ||
assert!(dialects.parse_sql_statements(sql).is_err()); | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.