-
Notifications
You must be signed in to change notification settings - Fork 630
feat: support alter schema for bigquery #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
base: main
Are you sure you want to change the base?
Conversation
src/ast/mod.rs
Outdated
AlterSchema { | ||
/// Schema name | ||
#[cfg_attr(feature = "visitor", visit(with = "visit_relation"))] | ||
name: ObjectName, | ||
if_exists: bool, | ||
operations: Vec<AlterSchemaOperation>, | ||
}, |
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)
@@ -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 comment
The 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 ALTER SCHEMA
statement. Also can we add some documentation for this function, ideally mentioning that it returns a Statement::AlterSchema
variant
src/parser/mod.rs
Outdated
AlterSchemaOperation::DropReplica { replica } | ||
} else { | ||
return self.expected_ref( | ||
"{SET OPTIONS | SET DEFAULT COLLATE | ADD REPLICA | DROP REPLICA}", |
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.
"{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
tests/sqlparser_bigquery.rs
Outdated
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'"); | ||
} | ||
|
||
#[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 merge these into a single test_alter_schema()
function?
Also we can move this to the sqlparser_common.rs file since the parser covers the statement it for all dialects (I imagine other dialects have some variant of this statement as well).
Also can we add scenarios for e.g.
ALTER SCHEMA DROP REPLICA;
ALTER SCHEMA SET OPTIONS ();
ALTER SCHEMA SET OPTIONS;
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.
postgres also has alter schema
, but it's quite different. https://www.postgresql.org/docs/17/sql-alterschema.html
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.
Ah right, yeah we can leave the tests in bigquery file as is
|
||
#[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 comment
The reason will be displayed to describe this comment to others. Learn more.
from the implementation, ADD REPLICA
takes in options, can we add test coverage for that behavior?
No description provided.