-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Support DROP SCHEMA statements #6096
Merged
+264
−13
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use std::borrow::Cow; | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] | ||
pub enum SchemaReference<'a> { | ||
Bare { | ||
schema: Cow<'a, str>, | ||
}, | ||
Full { | ||
schema: Cow<'a, str>, | ||
catalog: Cow<'a, str>, | ||
}, | ||
} | ||
|
||
impl SchemaReference<'_> { | ||
/// Get only the schema name that this references. | ||
pub fn schema_name(&self) -> &str { | ||
match self { | ||
SchemaReference::Bare { schema } => schema, | ||
SchemaReference::Full { schema, catalog: _ } => schema, | ||
} | ||
} | ||
} | ||
|
||
pub type OwnedSchemaReference = SchemaReference<'static>; | ||
|
||
impl std::fmt::Display for SchemaReference<'_> { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::Bare { schema } => write!(f, "{schema}"), | ||
Self::Full { schema, catalog } => write!(f, "{catalog}.{schema}"), | ||
} | ||
} | ||
} | ||
|
||
impl<'a> From<&'a OwnedSchemaReference> for SchemaReference<'a> { | ||
fn from(value: &'a OwnedSchemaReference) -> Self { | ||
match value { | ||
SchemaReference::Bare { schema } => SchemaReference::Bare { | ||
schema: Cow::Borrowed(schema), | ||
}, | ||
SchemaReference::Full { schema, catalog } => SchemaReference::Full { | ||
schema: Cow::Borrowed(schema), | ||
catalog: Cow::Borrowed(catalog), | ||
}, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -375,7 +375,7 @@ SHOW CREATE TABLE test.xyz | |
---- | ||
datafusion test xyz CREATE VIEW test.xyz AS SELECT * FROM abc | ||
|
||
statement error DataFusion error: This feature is not implemented: Only `DROP TABLE/VIEW | ||
statement error DataFusion error: Execution error: Cannot drop schema test because other tables depend on it: xyz | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
DROP SCHEMA test; | ||
|
||
statement ok | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -15,10 +15,10 @@ | |||||
// specific language governing permissions and limitations | ||||||
// under the License. | ||||||
|
||||||
use datafusion_common::Column; | ||||||
use datafusion_common::{ | ||||||
parsers::CompressionTypeVariant, DFSchemaRef, OwnedTableReference, | ||||||
}; | ||||||
use datafusion_common::{Column, OwnedSchemaReference}; | ||||||
use std::collections::HashMap; | ||||||
use std::sync::Arc; | ||||||
use std::{ | ||||||
|
@@ -45,6 +45,8 @@ pub enum DdlStatement { | |||||
DropTable(DropTable), | ||||||
/// Drops a view. | ||||||
DropView(DropView), | ||||||
/// Drops a catalog schema | ||||||
DropCatalogSchema(DropCatalogSchema), | ||||||
} | ||||||
|
||||||
impl DdlStatement { | ||||||
|
@@ -62,6 +64,7 @@ impl DdlStatement { | |||||
DdlStatement::CreateCatalog(CreateCatalog { schema, .. }) => schema, | ||||||
DdlStatement::DropTable(DropTable { schema, .. }) => schema, | ||||||
DdlStatement::DropView(DropView { schema, .. }) => schema, | ||||||
DdlStatement::DropCatalogSchema(DropCatalogSchema { schema, .. }) => schema, | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -76,6 +79,7 @@ impl DdlStatement { | |||||
DdlStatement::CreateCatalog(_) => "CreateCatalog", | ||||||
DdlStatement::DropTable(_) => "DropTable", | ||||||
DdlStatement::DropView(_) => "DropView", | ||||||
DdlStatement::DropCatalogSchema(_) => "DropCatalogSchema", | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -91,6 +95,7 @@ impl DdlStatement { | |||||
DdlStatement::CreateView(CreateView { input, .. }) => vec![input], | ||||||
DdlStatement::DropTable(_) => vec![], | ||||||
DdlStatement::DropView(_) => vec![], | ||||||
DdlStatement::DropCatalogSchema(_) => vec![], | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -147,6 +152,14 @@ impl DdlStatement { | |||||
}) => { | ||||||
write!(f, "DropView: {name:?} if not exist:={if_exists}") | ||||||
} | ||||||
DdlStatement::DropCatalogSchema(DropCatalogSchema { | ||||||
name, | ||||||
if_exists, | ||||||
cascade, | ||||||
.. | ||||||
}) => { | ||||||
write!(f, "DropCatalogSchema: {name:?} if not exist:={if_exists} cascade:={cascade}") | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
|
@@ -273,3 +286,16 @@ pub struct DropView { | |||||
/// Dummy schema | ||||||
pub schema: DFSchemaRef, | ||||||
} | ||||||
|
||||||
/// Drops a schema | ||||||
#[derive(Clone, PartialEq, Eq, Hash)] | ||||||
pub struct DropCatalogSchema { | ||||||
/// The schema name | ||||||
pub name: OwnedSchemaReference, | ||||||
/// If the schema exists | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
pub if_exists: bool, | ||||||
/// Whether drop should cascade | ||||||
pub cascade: bool, | ||||||
/// Dummy schema | ||||||
pub schema: DFSchemaRef, | ||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️ --nice documentation