feat(opertor): check if a database is in use before dropping it (#4035)

feat(opertor): check if database is in use before dropping it
This commit is contained in:
Eugene Tolbakov
2024-05-27 04:31:58 +01:00
committed by GitHub
parent 25d64255a3
commit af486ec0d0
6 changed files with 37 additions and 7 deletions

View File

@@ -256,6 +256,13 @@ pub enum Error {
location: Location,
},
#[snafu(display("Schema `{name}` is in use"))]
SchemaInUse {
name: String,
#[snafu(implicit)]
location: Location,
},
#[snafu(display("Table occurs error"))]
Table {
#[snafu(implicit)]
@@ -727,6 +734,7 @@ impl ErrorExt for Error {
| Error::IllegalPrimaryKeysDef { .. }
| Error::SchemaNotFound { .. }
| Error::SchemaExists { .. }
| Error::SchemaInUse { .. }
| Error::ColumnNotFound { .. }
| Error::BuildRegex { .. }
| Error::InvalidSchema { .. }

View File

@@ -68,9 +68,9 @@ use crate::error::{
CreateLogicalTablesSnafu, CreateTableInfoSnafu, DdlWithMultiCatalogsSnafu,
DdlWithMultiSchemasSnafu, DeserializePartitionSnafu, EmptyDdlExprSnafu, FlowNotFoundSnafu,
InvalidPartitionColumnsSnafu, InvalidPartitionRuleSnafu, InvalidTableNameSnafu,
InvalidViewNameSnafu, InvalidViewStmtSnafu, ParseSqlValueSnafu, Result, SchemaNotFoundSnafu,
SubstraitCodecSnafu, TableAlreadyExistsSnafu, TableMetadataManagerSnafu, TableNotFoundSnafu,
UnrecognizedTableOptionSnafu, ViewAlreadyExistsSnafu,
InvalidViewNameSnafu, InvalidViewStmtSnafu, ParseSqlValueSnafu, Result, SchemaInUseSnafu,
SchemaNotFoundSnafu, SubstraitCodecSnafu, TableAlreadyExistsSnafu, TableMetadataManagerSnafu,
TableNotFoundSnafu, UnrecognizedTableOptionSnafu, ViewAlreadyExistsSnafu,
};
use crate::expr_factory;
use crate::statement::show::create_partitions_stmt;
@@ -667,10 +667,14 @@ impl StatementExecutor {
.await
.context(CatalogSnafu)?
{
self.drop_database_procedure(catalog, schema, drop_if_exists, query_context)
.await?;
if schema == query_context.current_schema() {
SchemaInUseSnafu { name: schema }.fail()
} else {
self.drop_database_procedure(catalog, schema, drop_if_exists, query_context)
.await?;
Ok(Output::new_with_affected_rows(0))
Ok(Output::new_with_affected_rows(0))
}
} else if drop_if_exists {
// DROP TABLE IF EXISTS meets table not found - ignored
Ok(Output::new_with_affected_rows(0))