Skip to content

Commit

Permalink
remove check schema empty in fe
Browse files Browse the repository at this point in the history
Signed-off-by: xxchan <[email protected]>
  • Loading branch information
xxchan committed Nov 25, 2024
1 parent 08fb7d4 commit 84cbacf
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 50 deletions.
2 changes: 0 additions & 2 deletions src/frontend/src/catalog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ pub enum CatalogError {
NotFound(&'static str, String),
#[error("{0} with name {1} exists")]
Duplicated(&'static str, String),
#[error("cannot drop {0} {1} because {2} {3} depend on it")]
NotEmpty(&'static str, String, &'static str, String),
}

impl From<CatalogError> for RwError {
Expand Down
50 changes: 2 additions & 48 deletions src/frontend/src/handler/drop_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use risingwave_sqlparser::ast::{DropMode, ObjectName};

use super::RwPgResponse;
use crate::binder::Binder;
use crate::catalog::CatalogError;
use crate::error::{ErrorCode, Result};
use crate::handler::HandlerArgs;

Expand Down Expand Up @@ -62,24 +61,8 @@ pub async fn handle_drop_schema(
};
match mode {
Some(DropMode::Restrict) | None => {
if let Some(table) = schema.iter_user_table().next() {
return Err(CatalogError::NotEmpty(
"schema",
schema_name,
"table",
table.name.clone(),
)
.into());
}
if let Some(source) = schema.iter_source().next() {
return Err(CatalogError::NotEmpty(
"schema",
schema_name,
"source",
source.name.clone(),
)
.into());
}
// Note: we don't check if the schema is empty here.
// The check is done in meta `ensure_schema_empty`.
}
Some(DropMode::Cascade) => {
bail_not_implemented!(issue = 6773, "drop schema with cascade mode");
Expand All @@ -92,32 +75,3 @@ pub async fn handle_drop_schema(
catalog_writer.drop_schema(schema.id()).await?;
Ok(PgResponse::empty_result(StatementType::DROP_SCHEMA))
}

#[cfg(test)]
mod tests {
use crate::test_utils::LocalFrontend;

#[tokio::test]
async fn test_drop_schema() {
let frontend = LocalFrontend::new(Default::default()).await;
let session = frontend.session_ref();
let catalog_reader = session.env().catalog_reader();

frontend.run_sql("CREATE SCHEMA schema").await.unwrap();

frontend.run_sql("CREATE TABLE schema.table").await.unwrap();

assert!(frontend.run_sql("DROP SCHEMA schema").await.is_err());

frontend.run_sql("DROP TABLE schema.table").await.unwrap();

frontend.run_sql("DROP SCHEMA schema").await.unwrap();

let schema = catalog_reader
.read_guard()
.get_database_by_name("schema")
.ok()
.cloned();
assert!(schema.is_none());
}
}

0 comments on commit 84cbacf

Please sign in to comment.