mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-23 23:44:07 +00:00
BigQuery: support of CREATE VIEW IF NOT EXISTS (#1118)
This commit is contained in:
parent
8fae601743
commit
60baea4ae7
2 changed files with 31 additions and 1 deletions
|
@ -3482,7 +3482,7 @@ impl<'a> Parser<'a> {
|
|||
) -> Result<Statement, ParserError> {
|
||||
let materialized = self.parse_keyword(Keyword::MATERIALIZED);
|
||||
self.expect_keyword(Keyword::VIEW)?;
|
||||
let if_not_exists = dialect_of!(self is SQLiteDialect|GenericDialect)
|
||||
let if_not_exists = dialect_of!(self is BigQueryDialect|SQLiteDialect|GenericDialect)
|
||||
&& self.parse_keywords(&[Keyword::IF, Keyword::NOT, Keyword::EXISTS]);
|
||||
// Many dialects support `OR ALTER` right after `CREATE`, but we don't (yet).
|
||||
// ANSI SQL and Postgres support RECURSIVE here, but we don't support it either.
|
||||
|
|
|
@ -175,6 +175,36 @@ fn parse_create_view_with_options() {
|
|||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn parse_create_view_if_not_exists() {
|
||||
let sql = "CREATE VIEW IF NOT EXISTS mydataset.newview AS SELECT foo FROM bar";
|
||||
match bigquery().verified_stmt(sql) {
|
||||
Statement::CreateView {
|
||||
name,
|
||||
columns,
|
||||
query,
|
||||
or_replace,
|
||||
materialized,
|
||||
options,
|
||||
cluster_by,
|
||||
with_no_schema_binding: late_binding,
|
||||
if_not_exists,
|
||||
temporary,
|
||||
} => {
|
||||
assert_eq!("mydataset.newview", name.to_string());
|
||||
assert_eq!(Vec::<ViewColumnDef>::new(), columns);
|
||||
assert_eq!("SELECT foo FROM bar", query.to_string());
|
||||
assert!(!materialized);
|
||||
assert!(!or_replace);
|
||||
assert_eq!(options, CreateTableOptions::None);
|
||||
assert_eq!(cluster_by, vec![]);
|
||||
assert!(!late_binding);
|
||||
assert!(if_not_exists);
|
||||
assert!(!temporary);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_create_table_with_options() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue