Skip to content

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)

}
}

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?

Copy link
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks @chenkovsky!
cc @alamb

@iffyio iffyio changed the title feat: support alter schema for bigquery feat: Add ALTER SCHEMA support Aug 20, 2025
@iffyio iffyio merged commit cb7a51e into apache:main Aug 20, 2025
10 checks passed
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