-
Notifications
You must be signed in to change notification settings - Fork 666
feat: Add ALTER SCHEMA
support
#1980
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 | ||||
---|---|---|---|---|---|---|
|
@@ -9108,8 +9108,10 @@ impl<'a> Parser<'a> { | |||||
Keyword::POLICY, | ||||||
Keyword::CONNECTOR, | ||||||
Keyword::ICEBERG, | ||||||
Keyword::SCHEMA, | ||||||
])?; | ||||||
match object_type { | ||||||
Keyword::SCHEMA => self.parse_alter_schema(), | ||||||
Keyword::VIEW => self.parse_alter_view(), | ||||||
Keyword::TYPE => self.parse_alter_type(), | ||||||
Keyword::TABLE => self.parse_alter_table(false), | ||||||
|
@@ -9241,6 +9243,40 @@ impl<'a> Parser<'a> { | |||||
} | ||||||
} | ||||||
|
||||||
pub fn parse_alter_schema(&mut self) -> Result<Statement, ParserError> { | ||||||
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. We can call prev_token before invoking this method, so that it is self contained and able to parse a full |
||||||
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]); | ||||||
let name = self.parse_object_name(false)?; | ||||||
let operation = if self.parse_keywords(&[Keyword::SET, Keyword::OPTIONS]) { | ||||||
self.prev_token(); | ||||||
let options = self.parse_options(Keyword::OPTIONS)?; | ||||||
AlterSchemaOperation::SetOptionsParens { options } | ||||||
} else if self.parse_keywords(&[Keyword::SET, Keyword::DEFAULT, Keyword::COLLATE]) { | ||||||
let collate = self.parse_expr()?; | ||||||
AlterSchemaOperation::SetDefaultCollate { collate } | ||||||
} else if self.parse_keywords(&[Keyword::ADD, Keyword::REPLICA]) { | ||||||
let replica = self.parse_identifier()?; | ||||||
let options = if self.peek_keyword(Keyword::OPTIONS) { | ||||||
Some(self.parse_options(Keyword::OPTIONS)?) | ||||||
} else { | ||||||
None | ||||||
}; | ||||||
AlterSchemaOperation::AddReplica { replica, options } | ||||||
} else if self.parse_keywords(&[Keyword::DROP, Keyword::REPLICA]) { | ||||||
let replica = self.parse_identifier()?; | ||||||
AlterSchemaOperation::DropReplica { replica } | ||||||
} else { | ||||||
return self.expected_ref( | ||||||
"{SET OPTIONS | SET DEFAULT COLLATE | ADD REPLICA | DROP REPLICA}", | ||||||
|
"{SET OPTIONS | SET DEFAULT COLLATE | ADD REPLICA | DROP REPLICA}", | |
"ALTER SCHEMA operation", |
Thinking something generic, in order to avoid an maintaining a growing list that may potentially go out of sync
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2806,3 +2806,23 @@ fn test_begin_transaction() { | |
fn test_begin_statement() { | ||
bigquery().verified_stmt("BEGIN"); | ||
} | ||
|
||
#[test] | ||
fn test_alter_schema_default_collate() { | ||
bigquery_and_generic().verified_stmt("ALTER SCHEMA mydataset SET DEFAULT COLLATE 'und:ci'"); | ||
} | ||
|
||
#[test] | ||
fn test_alter_schema_add_replica() { | ||
bigquery_and_generic().verified_stmt("ALTER SCHEMA mydataset ADD REPLICA 'us'"); | ||
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. from the implementation, |
||
} | ||
|
||
#[test] | ||
fn test_alter_schema_drop_replica() { | ||
bigquery_and_generic().verified_stmt("ALTER SCHEMA mydataset DROP REPLICA 'us'"); | ||
} | ||
|
||
#[test] | ||
fn test_alter_schema_set_options() { | ||
bigquery_and_generic().verified_stmt("ALTER SCHEMA mydataset SET OPTIONS (location = 'us')"); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use a named struct syntax here? e.g.
AlterSchema(AlterSchemaStatement)