Skip to content

Commit

Permalink
try fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TCeason committed Jan 18, 2025
1 parent 3a32c18 commit 3fd50a6
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)));
}

Expand Down
38 changes: 36 additions & 2 deletions src/query/sql/src/planner/binder/ddl/procedure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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::<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(name.clone())),
name: ProcedureNameIdent::new(&tenant, ProcedureIdentity::from(new_name)),
meta,
})))
}
Expand All @@ -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::<Vec<String>>()
.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)),
})))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 3fd50a6

Please sign in to comment.