File tree Expand file tree Collapse file tree 2 files changed +48
-3
lines changed
src/query/sql/src/planner/binder/ddl
tests/sqllogictests/suites/base/15_procedure Expand file tree Collapse file tree 2 files changed +48
-3
lines changed Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff line change @@ -132,6 +132,19 @@ drop procedure p1(UInt8, UInt8);
132132statement ok
133133drop 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
136149statement ok
137150drop procedure if exists not_exists_p();
@@ -203,4 +216,3 @@ call procedure p3('x');
203216
204217statement ok
205218drop procedure p3(string);
206-
You can’t perform that action at this time.
0 commit comments