feat: Add ALTER SCHEMA support#1980
Conversation
| 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.
Can we use a named struct syntax here? e.g. AlterSchema(AlterSchemaStatement)
| } | ||
| } | ||
|
|
||
| pub fn parse_alter_schema(&mut self) -> Result<Statement, ParserError> { |
There was a problem hiding this comment.
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
| AlterSchemaOperation::DropReplica { replica } | ||
| } else { | ||
| return self.expected_ref( | ||
| "{SET OPTIONS | SET DEFAULT COLLATE | ADD REPLICA | DROP REPLICA}", |
There was a problem hiding this comment.
| "{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
| 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.
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.
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.
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.
from the implementation, ADD REPLICA takes in options, can we add test coverage for that behavior?
iffyio
left a comment
There was a problem hiding this comment.
LGTM! Thanks @chenkovsky!
cc @alamb
ALTER SCHEMA support
No description provided.