You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by gi...@apache.org on 2026/07/27 09:07:39 UTC
(datafusion-sqlparser-rs) 01/01: Accept CREATE OR REPLACE SCHEMA (#2396)
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-2396-09827e17dc58e563902f5e8d3fa4631a9ac07518
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git
commit 6f8a7160f15c136d7dd03fa478faa91fbfc9f01c
Author: sabir-akhadov-localstack <sa...@localstack.cloud>
AuthorDate: Mon Jul 27 11:07:13 2026 +0200
Accept CREATE OR REPLACE SCHEMA (#2396)
Co-authored-by: Przemek Denkiewicz <67...@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <no...@anthropic.com>
---
src/ast/mod.rs | 6 +++++-
src/parser/mod.rs | 9 +++++----
tests/sqlparser_common.rs | 19 +++++++++++++++++++
3 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/src/ast/mod.rs b/src/ast/mod.rs
index 3754e598..bf8a62cf 100644
--- a/src/ast/mod.rs
+++ b/src/ast/mod.rs
@@ -4346,6 +4346,8 @@ pub enum Statement {
CreateSchema {
/// `<schema name> | AUTHORIZATION <schema authorization identifier> | <schema name> AUTHORIZATION <schema authorization identifier>`
schema_name: SchemaName,
+ /// `true` when `OR REPLACE` was present.
+ or_replace: bool,
/// `true` when `IF NOT EXISTS` was present.
if_not_exists: bool,
/// Schema properties.
@@ -6016,6 +6018,7 @@ impl fmt::Display for Statement {
}
Statement::CreateSchema {
schema_name,
+ or_replace,
if_not_exists,
with,
options,
@@ -6024,7 +6027,8 @@ impl fmt::Display for Statement {
} => {
write!(
f,
- "CREATE SCHEMA {if_not_exists}{name}",
+ "CREATE {or_replace}SCHEMA {if_not_exists}{name}",
+ or_replace = if *or_replace { "OR REPLACE " } else { "" },
if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
name = schema_name
)?;
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index 294a0bed..524ddea4 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -5278,11 +5278,13 @@ impl<'a> Parser<'a> {
self.parse_create_secret(or_replace, temporary, persistent)
} else if self.parse_keyword(Keyword::USER) {
self.parse_create_user(or_replace).map(Into::into)
+ } else if self.parse_keyword(Keyword::SCHEMA) {
+ self.parse_create_schema(or_replace)
} else if self.parse_keyword(Keyword::WAREHOUSE) {
self.parse_create_warehouse(or_replace).map(Into::into)
} else if or_replace {
self.expected_ref(
- "[EXTERNAL] TABLE or [MATERIALIZED] VIEW or FUNCTION or WAREHOUSE after CREATE OR REPLACE",
+ "[EXTERNAL] TABLE or [MATERIALIZED] VIEW or FUNCTION or SCHEMA or WAREHOUSE after CREATE OR REPLACE",
self.peek_token_ref(),
)
} else if self.parse_keyword(Keyword::EXTENSION) {
@@ -5293,8 +5295,6 @@ impl<'a> Parser<'a> {
self.parse_create_index(true).map(Into::into)
} else if self.parse_keyword(Keyword::VIRTUAL) {
self.parse_create_virtual_table()
- } else if self.parse_keyword(Keyword::SCHEMA) {
- self.parse_create_schema()
} else if self.parse_keyword(Keyword::DATABASE) {
self.parse_create_database()
} else if self.parse_keyword(Keyword::ROLE) {
@@ -5624,7 +5624,7 @@ impl<'a> Parser<'a> {
}
/// Parse a `CREATE SCHEMA` statement.
- pub fn parse_create_schema(&mut self) -> Result<Statement, ParserError> {
+ pub fn parse_create_schema(&mut self, or_replace: bool) -> Result<Statement, ParserError> {
let if_not_exists = self.parse_keywords(&[Keyword::IF, Keyword::NOT, Keyword::EXISTS]);
let schema_name = self.parse_schema_name()?;
@@ -5655,6 +5655,7 @@ impl<'a> Parser<'a> {
Ok(Statement::CreateSchema {
schema_name,
+ or_replace,
if_not_exists,
with,
options,
diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs
index 5ff5e5c4..2e9884a5 100644
--- a/tests/sqlparser_common.rs
+++ b/tests/sqlparser_common.rs
@@ -4534,6 +4534,25 @@ fn parse_create_schema() {
verified_stmt(r#"CREATE SCHEMA a CLONE b"#);
}
+#[test]
+fn parse_create_or_replace_schema() {
+ match verified_stmt("CREATE OR REPLACE SCHEMA X") {
+ Statement::CreateSchema {
+ schema_name,
+ or_replace,
+ if_not_exists,
+ ..
+ } => {
+ assert_eq!(schema_name.to_string(), "X".to_owned());
+ assert!(or_replace);
+ assert!(!if_not_exists);
+ }
+ _ => unreachable!(),
+ }
+
+ verified_stmt("CREATE OR REPLACE SCHEMA IF NOT EXISTS X");
+}
+
#[test]
fn parse_create_schema_with_authorization() {
let sql = "CREATE SCHEMA AUTHORIZATION Y";
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org