Skip to content

Commit

Permalink
bigquery: ALTER SCHEMA SET OPTIONS
Browse files Browse the repository at this point in the history
  • Loading branch information
lustefaniak committed Mar 26, 2024
1 parent a0824d6 commit f66f248
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1705,6 +1705,13 @@ pub enum Statement {
with_options: Vec<SqlOption>,
set_options: Vec<SqlOption>,
},
/// ALTER SCHEMA
AlterSchema {
/// View name
#[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
name: ObjectName,
set_options: Vec<SqlOption>,
},
/// ALTER ROLE
AlterRole {
name: Ident,
Expand Down Expand Up @@ -3048,6 +3055,13 @@ impl fmt::Display for Statement {
}
Ok(())
}
Statement::AlterSchema { name, set_options } => {
write!(f, "ALTER SCHEMA {name}")?;
if !set_options.is_empty() {
write!(f, " SET OPTIONS ({})", display_comma_separated(set_options))?;
}
Ok(())
}
Statement::AlterRole { name, operation } => {
write!(f, "ALTER ROLE {name} {operation}")
}
Expand Down
13 changes: 13 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4856,6 +4856,7 @@ impl<'a> Parser<'a> {
Keyword::TABLE,
Keyword::INDEX,
Keyword::ROLE,
Keyword::SCHEMA,
])?;
match object_type {
Keyword::VIEW => self.parse_alter_view(),
Expand Down Expand Up @@ -4890,6 +4891,7 @@ impl<'a> Parser<'a> {
})
}
Keyword::ROLE => self.parse_alter_role(),
Keyword::SCHEMA => self.parse_alter_schema(),
// unreachable because expect_one_of_keywords used above
_ => unreachable!(),
}
Expand Down Expand Up @@ -4923,6 +4925,17 @@ impl<'a> Parser<'a> {
})
}

pub fn parse_alter_schema(&mut self) -> Result<Statement, ParserError> {
let name = self.parse_object_name()?;

self.expect_keywords(&[Keyword::SET, Keyword::OPTIONS])?;
self.prev_token();

let set_options = self.parse_options(Keyword::OPTIONS)?;

Ok(Statement::AlterSchema { name, set_options })
}

/// Parse a copy statement
pub fn parse_copy(&mut self) -> Result<Statement, ParserError> {
let source;
Expand Down
6 changes: 6 additions & 0 deletions tests/sqlparser_bigquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1302,3 +1302,9 @@ fn test_alter_table_set_options() {
fn test_alter_view_set_options() {
bigquery().verified_stmt("ALTER VIEW tbl SET OPTIONS (description = \"Desc.\")");
}

#[test]
fn test_alter_schema_set_options() {
bigquery()
.verified_stmt("ALTER SCHEMA mydataset SET OPTIONS (default_table_expiration_days = 3.75)");
}

0 comments on commit f66f248

Please sign in to comment.