This is an automated email from the ASF dual-hosted git repository.
iffyio pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git
The following commit(s) were added to refs/heads/main by this push:
new f81aed63 BigQuery: Add support for `CREATE SCHEMA` options (#1742)
f81aed63 is described below
commit f81aed6359d9da35df434a6b4b0df07b6cffd5c5
Author: Ifeanyi Ubah <[email protected]>
AuthorDate: Fri Mar 14 08:00:19 2025 +0100
BigQuery: Add support for `CREATE SCHEMA` options (#1742)
---
src/ast/mod.rs | 42 ++++++++++++++++++++++++++++++++++++------
src/parser/mod.rs | 14 ++++++++++++++
tests/sqlparser_common.rs | 5 +++++
tests/sqlparser_postgres.rs | 2 ++
4 files changed, 57 insertions(+), 6 deletions(-)
diff --git a/src/ast/mod.rs b/src/ast/mod.rs
index 66fd4c6f..8c407921 100644
--- a/src/ast/mod.rs
+++ b/src/ast/mod.rs
@@ -3450,6 +3450,22 @@ pub enum Statement {
/// `<schema name> | AUTHORIZATION <schema authorization identifier>
| <schema name> AUTHORIZATION <schema authorization identifier>`
schema_name: SchemaName,
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
/// CREATE DATABASE
@@ -5177,12 +5193,26 @@ impl fmt::Display for Statement {
Statement::CreateSchema {
schema_name,
if_not_exists,
- } => write!(
- f,
- "CREATE SCHEMA {if_not_exists}{name}",
- if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else {
"" },
- name = schema_name
- ),
+ options,
+ default_collate_spec,
+ } => {
+ write!(
+ 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 } => {
write!(f, "ASSERT {condition}")?;
if let Some(m) = message {
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index 3adfe55e..864fd579 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -4731,9 +4731,23 @@ impl<'a> Parser<'a> {
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 {
schema_name,
if_not_exists,
+ options,
+ default_collate_spec,
})
}
diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs
index 8c9cae83..c65cc6b5 100644
--- a/tests/sqlparser_common.rs
+++ b/tests/sqlparser_common.rs
@@ -4208,6 +4208,11 @@ fn parse_create_schema() {
}
_ => 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]
diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs
index 1a98870f..e62f2359 100644
--- a/tests/sqlparser_postgres.rs
+++ b/tests/sqlparser_postgres.rs
@@ -988,6 +988,8 @@ fn parse_create_schema_if_not_exists() {
Statement::CreateSchema {
if_not_exists: true,
schema_name,
+ options: _,
+ default_collate_spec: _,
} => assert_eq!("schema_name", schema_name.to_string()),
_ => unreachable!(),
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]