Skip to content

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

chenkovsky
Copy link
Contributor

No description provided.

src/ast/mod.rs Outdated
Comment on lines 3387 to 3393
AlterSchema {
/// Schema name
#[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
name: ObjectName,
if_exists: bool,
operations: Vec<AlterSchemaOperation>,
},
Copy link
Contributor

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> {
Copy link
Contributor

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

AlterSchemaOperation::DropReplica { replica }
} else {
return self.expected_ref(
"{SET OPTIONS | SET DEFAULT COLLATE | ADD REPLICA | DROP REPLICA}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"{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

Comment on lines 2811 to 2828
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')");
}
Copy link
Contributor

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;

Copy link
Contributor Author

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

Copy link
Contributor

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'");
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants