Skip to content

Commit

Permalink
drop old procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
TCeason committed Jan 19, 2025
1 parent 22ecb68 commit bd3f450
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 38 deletions.
20 changes: 16 additions & 4 deletions src/query/service/src/interpreters/interpreter_procedure_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,22 @@ impl Interpreter for DropProcedureInterpreter {
.drop_procedure(&drop_procedure_req.name_ident)
.await?;
if dropped.is_none() && !self.plan.if_exists {
return Err(ErrorCode::UnknownProcedure(format!(
"Unknown procedure '{}' while drop procedure",
drop_procedure_req.name_ident.procedure_name()
)));
{
// try drop old name:
let old_drop_procedure_req = DropProcedureReq {
name_ident: self.plan.old_name.clone(),
};
let dropped = UserApiProvider::instance()
.procedure_api(&tenant)
.drop_procedure(&old_drop_procedure_req.name_ident)
.await?;
if dropped.is_none() {
return Err(ErrorCode::UnknownProcedure(format!(
"Unknown procedure '{}' while drop procedure",
drop_procedure_req.name_ident.procedure_name()
)));
}
}
}

Ok(PipelineBuildResult::create())
Expand Down
66 changes: 32 additions & 34 deletions src/query/sql/src/planner/binder/ddl/procedure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use databend_common_ast::ast::CreateProcedureStmt;
use databend_common_ast::ast::DescProcedureStmt;
use databend_common_ast::ast::DropProcedureStmt;
use databend_common_ast::ast::ExecuteImmediateStmt;
use databend_common_ast::ast::ProcedureIdentity as AstProcedureIdentity;
use databend_common_ast::ast::ProcedureLanguage;
use databend_common_ast::ast::ProcedureType;
use databend_common_ast::ast::ShowOptions;
Expand All @@ -28,6 +29,7 @@ use databend_common_meta_app::principal::GetProcedureReq;
use databend_common_meta_app::principal::ProcedureIdentity;
use databend_common_meta_app::principal::ProcedureMeta;
use databend_common_meta_app::principal::ProcedureNameIdent;
use databend_common_meta_app::tenant::Tenant;
use databend_common_users::UserApiProvider;

use crate::binder::show::get_show_options;
Expand Down Expand Up @@ -74,26 +76,11 @@ impl Binder {
// 2. need check script's return type and stmt.return_type

let meta = self.procedure_meta(return_type, script, comment, language, args)?;
let mut args_type = vec![];
for arg in name.args_type.split(',') {
args_type.push(DataType::from(&resolve_type_name_by_str(arg, true)?));
}
let new_name = databend_common_ast::ast::ProcedureIdentity {
name: name.name.to_string(),
args_type: if args_type.is_empty() {
"".to_string()
} else {
args_type
.iter()
.map(|arg| arg.to_string())
.collect::<Vec<String>>()
.join(",")
},
};

Ok(Plan::CreateProcedure(Box::new(CreateProcedurePlan {
create_option: create_option.clone().into(),
tenant: tenant.to_owned(),
name: ProcedureNameIdent::new(&tenant, ProcedureIdentity::from(new_name)),
name: generate_procedure_name_ident(&tenant, name)?,
meta,
})))
}
Expand All @@ -102,26 +89,11 @@ impl Binder {
let DropProcedureStmt { name, if_exists } = stmt;

let tenant = self.ctx.get_tenant();
let mut args_type = vec![];
for arg in name.args_type.split(',') {
args_type.push(DataType::from(&resolve_type_name_by_str(arg, true)?));
}
let new_name = databend_common_ast::ast::ProcedureIdentity {
name: name.name.to_string(),
args_type: if args_type.is_empty() {
"".to_string()
} else {
args_type
.iter()
.map(|arg| arg.to_string())
.collect::<Vec<String>>()
.join(",")
},
};
Ok(Plan::DropProcedure(Box::new(DropProcedurePlan {
if_exists: *if_exists,
tenant: tenant.to_owned(),
name: ProcedureNameIdent::new(tenant, ProcedureIdentity::from(new_name)),
name: generate_procedure_name_ident(&tenant, name)?,
old_name: ProcedureNameIdent::new(tenant, ProcedureIdentity::from(name.clone())),
})))
}

Expand Down Expand Up @@ -242,3 +214,29 @@ impl Binder {
})
}
}

fn generate_procedure_name_ident(
tenant: &Tenant,
name: &AstProcedureIdentity,
) -> Result<ProcedureNameIdent> {
if name.args_type.is_empty() {
return Ok(ProcedureNameIdent::new(tenant, name.clone().into()));
}

let mut args_type = vec![];
for arg in name.args_type.split(',') {
args_type.push(DataType::from(&resolve_type_name_by_str(arg, true)?));
}
let new_name = databend_common_ast::ast::ProcedureIdentity {
name: name.name.to_string(),
args_type: args_type
.iter()
.map(|arg| arg.to_string())
.collect::<Vec<String>>()
.join(","),
};
Ok(ProcedureNameIdent::new(
tenant,
ProcedureIdentity::from(new_name),
))
}
1 change: 1 addition & 0 deletions src/query/sql/src/planner/plans/ddl/procedure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub struct DropProcedurePlan {
pub if_exists: bool,
pub tenant: Tenant,
pub name: ProcedureNameIdent,
pub old_name: ProcedureNameIdent,
}

impl From<DropProcedurePlan> for DropProcedureReq {
Expand Down

0 comments on commit bd3f450

Please sign in to comment.