Skip to content

biquery: CREATE VIEW OPTIONS #35

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

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,7 @@ pub enum Statement {
late_binding: bool,
auto_refresh: Option<bool>,
comment: Option<String>,
view_options: Vec<SqlOption>,
},
/// CREATE TABLE
CreateTable {
Expand Down Expand Up @@ -2535,6 +2536,7 @@ impl fmt::Display for Statement {
late_binding,
auto_refresh,
comment,
view_options,
} => {
write!(
f,
Expand Down Expand Up @@ -2590,6 +2592,14 @@ impl fmt::Display for Statement {
write!(f, " COMMENT='{comment}'")?;
}

if !view_options.is_empty() {
write!(
f,
" OPTIONS({view_options})",
view_options = display_comma_separated(view_options)
)?;
}

write!(f, " AS {query}")?;

if *late_binding {
Expand Down
3 changes: 3 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3347,6 +3347,8 @@ impl<'a> Parser<'a> {
None
};

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

self.expect_keyword(Keyword::AS)?;
let query = Box::new(self.parse_query()?);
// Optional `WITH [ CASCADED | LOCAL ] CHECK OPTION` is widely supported here.
Expand Down Expand Up @@ -3377,6 +3379,7 @@ impl<'a> Parser<'a> {
late_binding,
auto_refresh,
comment,
view_options,
})
}

Expand Down
7 changes: 7 additions & 0 deletions tests/sqlparser_bigquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1285,3 +1285,10 @@ fn test_create_table_field_options() {
"CREATE TABLE `pr`.`ts`.`salesforce_accounts` (account_name STRING OPTIONS(description = \"Account name\", label = \"dev\"))",
);
}

#[test]
fn test_create_view_options() {
bigquery().verified_stmt(
"CREATE VIEW `myproject`.`mydataset`.`newview` OPTIONS(friendly_name = \"newview\", description = \"a view that expires in 2 days\") AS SELECT col_1 FROM `myproject`.`mydataset`.`mytable`",
);
}
12 changes: 12 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5703,6 +5703,7 @@ fn parse_create_view() {
late_binding,
auto_refresh,
comment,
view_options,
} => {
assert_eq!("myschema.myview", name.to_string());
assert_eq!(Vec::<WithSpan<Ident>>::new(), columns);
Expand All @@ -5721,6 +5722,7 @@ fn parse_create_view() {
assert_eq!(late_binding, false);
assert_eq!(auto_refresh, None);
assert_eq!(comment, None);
assert_eq!(view_options, vec![]);
}
_ => unreachable!(),
}
Expand Down Expand Up @@ -5771,6 +5773,7 @@ fn parse_create_view_with_columns() {
late_binding,
auto_refresh,
comment,
view_options,
} => {
assert_eq!("v", name.to_string());
assert_eq!(
Expand All @@ -5795,6 +5798,7 @@ fn parse_create_view_with_columns() {
assert_eq!(late_binding, false);
assert_eq!(auto_refresh, None);
assert_eq!(comment, None);
assert_eq!(view_options, vec![]);
}
_ => unreachable!(),
}
Expand Down Expand Up @@ -5822,6 +5826,7 @@ fn parse_create_or_replace_view() {
late_binding,
auto_refresh,
comment,
view_options,
} => {
assert_eq!("v", name.to_string());
assert_eq!(columns, vec![]);
Expand All @@ -5840,6 +5845,7 @@ fn parse_create_or_replace_view() {
assert_eq!(late_binding, false);
assert_eq!(auto_refresh, None);
assert_eq!(comment, None);
assert_eq!(view_options, vec![]);
}
_ => unreachable!(),
}
Expand Down Expand Up @@ -5871,6 +5877,7 @@ fn parse_create_or_replace_materialized_view() {
late_binding,
auto_refresh,
comment,
view_options,
} => {
assert_eq!("v", name.to_string());
assert_eq!(columns, vec![]);
Expand All @@ -5889,6 +5896,7 @@ fn parse_create_or_replace_materialized_view() {
assert_eq!(late_binding, false);
assert_eq!(auto_refresh, None);
assert_eq!(comment, None);
assert_eq!(view_options, vec![]);
}
_ => unreachable!(),
}
Expand Down Expand Up @@ -5916,6 +5924,7 @@ fn parse_create_materialized_view() {
late_binding,
auto_refresh,
comment,
view_options,
} => {
assert_eq!("myschema.myview", name.to_string());
assert_eq!(Vec::<WithSpan<Ident>>::new(), columns);
Expand All @@ -5934,6 +5943,7 @@ fn parse_create_materialized_view() {
assert_eq!(late_binding, false);
assert_eq!(auto_refresh, None);
assert_eq!(comment, None);
assert_eq!(view_options, vec![]);
}
_ => unreachable!(),
}
Expand Down Expand Up @@ -5961,6 +5971,7 @@ fn parse_create_materialized_view_with_cluster_by() {
late_binding,
auto_refresh,
comment,
view_options,
} => {
assert_eq!("myschema.myview", name.to_string());
assert_eq!(Vec::<WithSpan<Ident>>::new(), columns);
Expand All @@ -5979,6 +5990,7 @@ fn parse_create_materialized_view_with_cluster_by() {
assert_eq!(late_binding, false);
assert_eq!(auto_refresh, None);
assert_eq!(comment, None);
assert_eq!(view_options, vec![]);
}
_ => unreachable!(),
}
Expand Down
Loading