From bd3f4507324791ef0acc3e7edcc8186070b6707e Mon Sep 17 00:00:00 2001 From: TCeason Date: Sun, 19 Jan 2025 10:02:15 +0800 Subject: [PATCH] drop old procedure --- .../interpreter_procedure_drop.rs | 20 ++++-- .../sql/src/planner/binder/ddl/procedure.rs | 66 +++++++++---------- .../sql/src/planner/plans/ddl/procedure.rs | 1 + 3 files changed, 49 insertions(+), 38 deletions(-) diff --git a/src/query/service/src/interpreters/interpreter_procedure_drop.rs b/src/query/service/src/interpreters/interpreter_procedure_drop.rs index 83e1f85b68c96..a3c454e4297ac 100644 --- a/src/query/service/src/interpreters/interpreter_procedure_drop.rs +++ b/src/query/service/src/interpreters/interpreter_procedure_drop.rs @@ -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()) diff --git a/src/query/sql/src/planner/binder/ddl/procedure.rs b/src/query/sql/src/planner/binder/ddl/procedure.rs index bb4171778012d..fe9460734f8b5 100644 --- a/src/query/sql/src/planner/binder/ddl/procedure.rs +++ b/src/query/sql/src/planner/binder/ddl/procedure.rs @@ -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; @@ -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; @@ -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::>() - .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, }))) } @@ -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::>() - .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())), }))) } @@ -242,3 +214,29 @@ impl Binder { }) } } + +fn generate_procedure_name_ident( + tenant: &Tenant, + name: &AstProcedureIdentity, +) -> Result { + 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::>() + .join(","), + }; + Ok(ProcedureNameIdent::new( + tenant, + ProcedureIdentity::from(new_name), + )) +} diff --git a/src/query/sql/src/planner/plans/ddl/procedure.rs b/src/query/sql/src/planner/plans/ddl/procedure.rs index 4104c34ebfe25..c877d6bac76ab 100644 --- a/src/query/sql/src/planner/plans/ddl/procedure.rs +++ b/src/query/sql/src/planner/plans/ddl/procedure.rs @@ -66,6 +66,7 @@ pub struct DropProcedurePlan { pub if_exists: bool, pub tenant: Tenant, pub name: ProcedureNameIdent, + pub old_name: ProcedureNameIdent, } impl From for DropProcedureReq {