mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-04 06:18:17 +00:00
BigQuery: Add support for CREATE SCHEMA
options (#1742)
This commit is contained in:
parent
862e887a66
commit
f81aed6359
4 changed files with 57 additions and 6 deletions
|
@ -3450,6 +3450,22 @@ pub enum Statement {
|
||||||
/// `<schema name> | AUTHORIZATION <schema authorization identifier> | <schema name> AUTHORIZATION <schema authorization identifier>`
|
/// `<schema name> | AUTHORIZATION <schema authorization identifier> | <schema name> AUTHORIZATION <schema authorization identifier>`
|
||||||
schema_name: SchemaName,
|
schema_name: SchemaName,
|
||||||
if_not_exists: bool,
|
if_not_exists: bool,
|
||||||
|
/// Schema options.
|
||||||
|
///
|
||||||
|
/// ```sql
|
||||||
|
/// CREATE SCHEMA myschema OPTIONS(key1='value1');
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#create_schema_statement)
|
||||||
|
options: Option<Vec<SqlOption>>,
|
||||||
|
/// Default collation specification for the schema.
|
||||||
|
///
|
||||||
|
/// ```sql
|
||||||
|
/// CREATE SCHEMA myschema DEFAULT COLLATE 'und:ci';
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#create_schema_statement)
|
||||||
|
default_collate_spec: Option<Expr>,
|
||||||
},
|
},
|
||||||
/// ```sql
|
/// ```sql
|
||||||
/// CREATE DATABASE
|
/// CREATE DATABASE
|
||||||
|
@ -5177,12 +5193,26 @@ impl fmt::Display for Statement {
|
||||||
Statement::CreateSchema {
|
Statement::CreateSchema {
|
||||||
schema_name,
|
schema_name,
|
||||||
if_not_exists,
|
if_not_exists,
|
||||||
} => write!(
|
options,
|
||||||
f,
|
default_collate_spec,
|
||||||
"CREATE SCHEMA {if_not_exists}{name}",
|
} => {
|
||||||
if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
|
write!(
|
||||||
name = schema_name
|
f,
|
||||||
),
|
"CREATE SCHEMA {if_not_exists}{name}",
|
||||||
|
if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
|
||||||
|
name = schema_name
|
||||||
|
)?;
|
||||||
|
|
||||||
|
if let Some(collate) = default_collate_spec {
|
||||||
|
write!(f, " DEFAULT COLLATE {collate}")?;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(options) = options {
|
||||||
|
write!(f, " OPTIONS({})", display_comma_separated(options))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Statement::Assert { condition, message } => {
|
Statement::Assert { condition, message } => {
|
||||||
write!(f, "ASSERT {condition}")?;
|
write!(f, "ASSERT {condition}")?;
|
||||||
if let Some(m) = message {
|
if let Some(m) = message {
|
||||||
|
|
|
@ -4731,9 +4731,23 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
let schema_name = self.parse_schema_name()?;
|
let schema_name = self.parse_schema_name()?;
|
||||||
|
|
||||||
|
let default_collate_spec = if self.parse_keywords(&[Keyword::DEFAULT, Keyword::COLLATE]) {
|
||||||
|
Some(self.parse_expr()?)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
let options = if self.peek_keyword(Keyword::OPTIONS) {
|
||||||
|
Some(self.parse_options(Keyword::OPTIONS)?)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
Ok(Statement::CreateSchema {
|
Ok(Statement::CreateSchema {
|
||||||
schema_name,
|
schema_name,
|
||||||
if_not_exists,
|
if_not_exists,
|
||||||
|
options,
|
||||||
|
default_collate_spec,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4208,6 +4208,11 @@ fn parse_create_schema() {
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
verified_stmt(r#"CREATE SCHEMA a.b.c OPTIONS(key1 = 'value1', key2 = 'value2')"#);
|
||||||
|
verified_stmt(r#"CREATE SCHEMA IF NOT EXISTS a OPTIONS(key1 = 'value1')"#);
|
||||||
|
verified_stmt(r#"CREATE SCHEMA IF NOT EXISTS a OPTIONS()"#);
|
||||||
|
verified_stmt(r#"CREATE SCHEMA IF NOT EXISTS a DEFAULT COLLATE 'und:ci' OPTIONS()"#);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -988,6 +988,8 @@ fn parse_create_schema_if_not_exists() {
|
||||||
Statement::CreateSchema {
|
Statement::CreateSchema {
|
||||||
if_not_exists: true,
|
if_not_exists: true,
|
||||||
schema_name,
|
schema_name,
|
||||||
|
options: _,
|
||||||
|
default_collate_spec: _,
|
||||||
} => assert_eq!("schema_name", schema_name.to_string()),
|
} => assert_eq!("schema_name", schema_name.to_string()),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue