From 3fd50a675bd53abbab5317eb432c4605b6cd7690 Mon Sep 17 00:00:00 2001 From: TCeason Date: Sat, 18 Jan 2025 22:19:57 +0800 Subject: [PATCH] try fix --- .../interpreter_procedure_create.rs | 1 + .../interpreter_procedure_drop.rs | 2 +- .../sql/src/planner/binder/ddl/procedure.rs | 38 ++++++++++++++++++- .../base/15_procedure/15_0002_procedure.test | 15 ++++++++ 4 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/query/service/src/interpreters/interpreter_procedure_create.rs b/src/query/service/src/interpreters/interpreter_procedure_create.rs index c026e8ec561a1..a27ecdfeca22d 100644 --- a/src/query/service/src/interpreters/interpreter_procedure_create.rs +++ b/src/query/service/src/interpreters/interpreter_procedure_create.rs @@ -57,6 +57,7 @@ impl Interpreter for CreateProcedureInterpreter { let tenant = self.plan.tenant.clone(); let create_procedure_req: CreateProcedureReq = self.plan.clone().into(); + println!("create_procedure_req is {:?}", create_procedure_req); let overriding = self.plan.create_option.is_overriding(); if UserApiProvider::instance() diff --git a/src/query/service/src/interpreters/interpreter_procedure_drop.rs b/src/query/service/src/interpreters/interpreter_procedure_drop.rs index 3d0a17c2d1c15..83e1f85b68c96 100644 --- a/src/query/service/src/interpreters/interpreter_procedure_drop.rs +++ b/src/query/service/src/interpreters/interpreter_procedure_drop.rs @@ -64,7 +64,7 @@ impl Interpreter for DropProcedureInterpreter { if dropped.is_none() && !self.plan.if_exists { return Err(ErrorCode::UnknownProcedure(format!( "Unknown procedure '{}' while drop procedure", - drop_procedure_req.name_ident + drop_procedure_req.name_ident.procedure_name() ))); } diff --git a/src/query/sql/src/planner/binder/ddl/procedure.rs b/src/query/sql/src/planner/binder/ddl/procedure.rs index 02a9c32539ce3..352918dbb94e6 100644 --- a/src/query/sql/src/planner/binder/ddl/procedure.rs +++ b/src/query/sql/src/planner/binder/ddl/procedure.rs @@ -21,6 +21,7 @@ use databend_common_ast::ast::ExecuteImmediateStmt; use databend_common_ast::ast::ProcedureLanguage; use databend_common_ast::ast::ProcedureType; use databend_common_ast::ast::ShowOptions; +use databend_common_ast::ast::TypeName; use databend_common_exception::ErrorCode; use databend_common_exception::Result; use databend_common_expression::types::DataType; @@ -39,6 +40,7 @@ use crate::plans::Plan; use crate::plans::RewriteKind; use crate::plans::SubqueryType; use crate::resolve_type_name; +use crate::resolve_type_name_by_str; use crate::BindContext; use crate::Binder; use crate::ScalarExpr; @@ -73,10 +75,26 @@ 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(name.clone())), + name: ProcedureNameIdent::new(&tenant, ProcedureIdentity::from(new_name)), meta, }))) } @@ -85,10 +103,26 @@ 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(name.clone())), + name: ProcedureNameIdent::new(tenant, ProcedureIdentity::from(new_name)), }))) } diff --git a/tests/sqllogictests/suites/base/15_procedure/15_0002_procedure.test b/tests/sqllogictests/suites/base/15_procedure/15_0002_procedure.test index 1142ef478a618..201e5aa1448f5 100644 --- a/tests/sqllogictests/suites/base/15_procedure/15_0002_procedure.test +++ b/tests/sqllogictests/suites/base/15_procedure/15_0002_procedure.test @@ -155,5 +155,20 @@ call procedure sum_even_numbers(1::INT, 2::INT) statement ok drop procedure sum_even_numbers(Int, Int); +statement ok +CREATE PROCEDURE if not exists p2(x STRING) RETURNS Int32 NOT NULL LANGUAGE SQL COMMENT='test' AS $$ +BEGIN + RETURN x; +END; +$$; + +query T +call procedure p2('x'); +---- +'x' + +statement ok +drop procedure p2(string); + statement ok unset global enable_experimental_procedure;