Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/meta/app/src/principal/procedure_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ impl KeyCodec for ProcedureIdentity {

impl From<databend_common_ast::ast::ProcedureIdentity> for ProcedureIdentity {
fn from(procedure: databend_common_ast::ast::ProcedureIdentity) -> Self {
ProcedureIdentity::new(procedure.name, procedure.args_type)
let args_type_str = procedure
.args_type
.iter()
.map(|t| t.to_string())
.collect::<Vec<_>>()
.join(",");
ProcedureIdentity::new(procedure.name, args_type_str)
}
}
32 changes: 29 additions & 3 deletions src/query/ast/src/ast/statements/procedure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,41 @@ impl Display for ProcedureLanguage {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)]
#[derive(Clone, PartialEq, Drive, DriveMut)]
pub struct ProcedureIdentity {
pub name: String,
pub args_type: String,
pub args_type: Vec<TypeName>,
}

impl std::fmt::Debug for ProcedureIdentity {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ProcedureIdentity")
.field("name", &self.name)
.field(
"args_type",
&self
.args_type
.iter()
.map(|t| t.to_string())
.collect::<Vec<_>>()
.join(","),
)
.finish()
}
}

impl Display for ProcedureIdentity {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(f, "{}({})", &self.name, &self.args_type,)
write!(
f,
"{}({})",
&self.name,
self.args_type
.iter()
.map(|t| t.to_string())
.collect::<Vec<_>>()
.join(",")
)
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/query/ast/src/ast/statements/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl Display for AlterUserStmt {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)]
#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
pub struct GrantStmt {
pub source: AccountMgrSource,
pub principal: PrincipalIdentity,
Expand All @@ -120,7 +120,7 @@ impl Display for GrantStmt {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)]
#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
pub struct RevokeStmt {
pub source: AccountMgrSource,
pub principal: PrincipalIdentity,
Expand Down Expand Up @@ -205,7 +205,7 @@ impl Display for ShowObjectPrivilegesStmt {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)]
#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
pub enum AccountMgrSource {
Role {
role: String,
Expand Down Expand Up @@ -239,7 +239,7 @@ impl Display for AccountMgrSource {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)]
#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
pub enum AccountMgrLevel {
Global,
Database(Option<String>),
Expand Down
61 changes: 8 additions & 53 deletions src/query/ast/src/parser/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2489,12 +2489,9 @@ pub fn statement_body(i: Input) -> IResult<Statement> {
let name = ProcedureIdentity {
name: name.to_string(),
args_type: if let Some(args) = &args {
args.iter()
.map(|arg| arg.data_type.to_string())
.collect::<Vec<String>>()
.join(",")
args.iter().map(|arg| arg.data_type.clone()).collect()
} else {
"".to_string()
vec![]
},
};
let stmt = CreateProcedureStmt {
Expand Down Expand Up @@ -2558,14 +2555,7 @@ pub fn statement_body(i: Input) -> IResult<Statement> {
if_exists: opt_if_exists.is_some(),
name: ProcedureIdentity {
name: name.to_string(),
args_type: if args.is_empty() {
"".to_string()
} else {
args.iter()
.map(|arg| arg.to_string())
.collect::<Vec<String>>()
.join(",")
},
args_type: args,
},
})
},
Expand All @@ -2579,14 +2569,7 @@ pub fn statement_body(i: Input) -> IResult<Statement> {
Statement::DescProcedure(DescProcedureStmt {
name: ProcedureIdentity {
name: name.to_string(),
args_type: if args.is_empty() {
"".to_string()
} else {
args.iter()
.map(|arg| arg.to_string())
.collect::<Vec<String>>()
.join(",")
},
args_type: args,
},
})
},
Expand Down Expand Up @@ -3636,14 +3619,7 @@ pub fn grant_source(i: Input) -> IResult<AccountMgrSource> {
privileges: vec![UserPrivilegeType::AccessProcedure],
level: AccountMgrLevel::Procedure(ProcedureIdentity {
name: name.to_string(),
args_type: if args.is_empty() {
"".to_string()
} else {
args.iter()
.map(|arg| arg.to_string())
.collect::<Vec<String>>()
.join(",")
},
args_type: args,
}),
},
);
Expand All @@ -3656,14 +3632,7 @@ pub fn grant_source(i: Input) -> IResult<AccountMgrSource> {
privileges: vec![UserPrivilegeType::AccessProcedure],
level: AccountMgrLevel::Procedure(ProcedureIdentity {
name: name.to_string(),
args_type: if args.is_empty() {
"".to_string()
} else {
args.iter()
.map(|arg| arg.to_string())
.collect::<Vec<String>>()
.join(",")
},
args_type: args,
}),
},
);
Expand Down Expand Up @@ -3833,14 +3802,7 @@ pub fn on_object_name(i: Input) -> IResult<GrantObjectName> {
|(_, name, args)| {
GrantObjectName::Procedure(ProcedureIdentity {
name: name.to_string(),
args_type: if args.is_empty() {
"".to_string()
} else {
args.iter()
.map(|arg| arg.to_string())
.collect::<Vec<String>>()
.join(",")
},
args_type: args,
})
},
);
Expand Down Expand Up @@ -3979,14 +3941,7 @@ pub fn grant_ownership_level(i: Input) -> IResult<AccountMgrLevel> {
|(_, name, args)| {
let name = ProcedureIdentity {
name: name.to_string(),
args_type: if args.is_empty() {
"".to_string()
} else {
args.iter()
.map(|arg| arg.to_string())
.collect::<Vec<String>>()
.join(",")
},
args_type: args,
};
AccountMgrLevel::Procedure(name)
},
Expand Down
28 changes: 14 additions & 14 deletions src/query/sql/src/planner/binder/ddl/procedure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ 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 @@ -266,20 +265,21 @@ fn generate_procedure_name_ident(
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(","),
};
let args_data_type: Vec<DataType> = name
.args_type
.iter()
.map(|type_name| resolve_type_name(type_name, true).map(|t| DataType::from(&t)))
.collect::<Result<Vec<_>, _>>()?;

// Convert normalized DataType back to string for storage
let args_type_str = args_data_type
.iter()
.map(|dt| dt.to_string())
.collect::<Vec<_>>()
.join(",");

Ok(ProcedureNameIdent::new(
tenant,
ProcedureIdentity::from(new_name),
ProcedureIdentity::new(name.name.clone(), args_type_str),
))
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@ drop procedure p1(UInt8, UInt8);
statement ok
drop procedure p1(int);

statement ok
CREATE OR REPLACE PROCEDURE p_decimal_arg(x Decimal(4, 2)) RETURNS Decimal(4, 2) LANGUAGE SQL COMMENT='decimal arg' AS $$
BEGIN
RETURN x;
END;
$$;

statement ok
desc procedure p_decimal_arg(Decimal(4, 2));

statement ok
drop procedure p_decimal_arg(Decimal(4, 2));


statement ok
drop procedure if exists not_exists_p();
Expand Down Expand Up @@ -203,4 +216,3 @@ call procedure p3('x');

statement ok
drop procedure p3(string);