Skip to content

Commit 681dead

Browse files
committed
fix(query): handle complex types in procedure argument parsing
Fixed procedure argument type parsing to correctly handle types with nested parentheses like Decimal(4, 2).
1 parent 5b874fa commit 681dead

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

src/query/sql/src/planner/binder/ddl/procedure.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,10 @@ fn generate_procedure_name_ident(
266266
return Ok(ProcedureNameIdent::new(tenant, name.clone().into()));
267267
}
268268

269+
let args = split_procedure_arg_types(&name.args_type)?;
269270
let mut args_type = vec![];
270-
for arg in name.args_type.split(',') {
271-
args_type.push(DataType::from(&resolve_type_name_by_str(arg, true)?));
271+
for arg in args {
272+
args_type.push(DataType::from(&resolve_type_name_by_str(&arg, true)?));
272273
}
273274
let new_name = databend_common_ast::ast::ProcedureIdentity {
274275
name: name.name.to_string(),
@@ -283,3 +284,35 @@ fn generate_procedure_name_ident(
283284
ProcedureIdentity::from(new_name),
284285
))
285286
}
287+
288+
fn split_procedure_arg_types(raw: &str) -> Result<Vec<String>> {
289+
let mut parts = Vec::new();
290+
let mut depth = 0;
291+
let mut start = 0;
292+
293+
for (i, c) in raw.char_indices() {
294+
match c {
295+
'(' => depth += 1,
296+
')' => depth -= 1,
297+
',' if depth == 0 => {
298+
let arg = raw[start..i].trim();
299+
if !arg.is_empty() {
300+
parts.push(arg.to_string());
301+
}
302+
start = i + 1;
303+
}
304+
_ => {}
305+
}
306+
}
307+
308+
if depth != 0 {
309+
return Err(ErrorCode::SyntaxException("unmatched parentheses"));
310+
}
311+
312+
let last = raw[start..].trim();
313+
if !last.is_empty() {
314+
parts.push(last.to_string());
315+
}
316+
317+
Ok(parts)
318+
}

tests/sqllogictests/suites/base/15_procedure/15_0002_procedure.test

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,19 @@ drop procedure p1(UInt8, UInt8);
132132
statement ok
133133
drop procedure p1(int);
134134

135+
statement ok
136+
CREATE OR REPLACE PROCEDURE p_decimal_arg(x Decimal(4, 2)) RETURNS Decimal(4, 2) LANGUAGE SQL COMMENT='decimal arg' AS $$
137+
BEGIN
138+
RETURN x;
139+
END;
140+
$$;
141+
142+
statement ok
143+
desc procedure p_decimal_arg(Decimal(4, 2));
144+
145+
statement ok
146+
drop procedure p_decimal_arg(Decimal(4, 2));
147+
135148

136149
statement ok
137150
drop procedure if exists not_exists_p();
@@ -203,4 +216,3 @@ call procedure p3('x');
203216

204217
statement ok
205218
drop procedure p3(string);
206-

0 commit comments

Comments
 (0)