Skip to content

Commit

Permalink
add related test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
xzhseh committed Jan 29, 2024
1 parent 60fc4f3 commit b1204f1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion e2e_test/udf/sql_udf.slt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ create function print_add_two(INT) returns int language sql as 'select print($1
statement error failed to conduct semantic check, please see if you are calling non-existence functions
create function non_exist(INT) returns int language sql as 'select yo(114514)';

# Try to create an anonymous sql udf whose return type mismatches with the sql body definition
statement error return type mismatch detected
create function type_mismatch(INT) returns varchar language sql as 'select $1 + 114514 + $1';

# A valid example
statement ok
create function type_match(INT) returns varchar language sql as $$select '$1 + 114514 + $1'$$;

query T
select type_match(114514);
----
$1 + 114514 + $1

# Call the defined sql udf
query I
select add(1, -1);
Expand Down Expand Up @@ -189,7 +202,7 @@ create function add_sub(INT, FLOAT, INT) returns float language sql as $$select

# Complex types interleaving
statement ok
create function add_sub_types(INT, BIGINT, FLOAT, DECIMAL, REAL) returns real language sql as 'select $1 + $2 - $3 + $4 + $5';
create function add_sub_types(INT, BIGINT, FLOAT, DECIMAL, REAL) returns double language sql as 'select $1 + $2 - $3 + $4 + $5';

statement ok
create function add_sub_return(INT, FLOAT, INT) returns float language sql return -$1 + $2 - $3;
Expand Down Expand Up @@ -290,6 +303,9 @@ drop function print_add_two;
statement ok
drop function regexp_replace_wrapper;

statement ok
drop function type_match;

# Drop the mock table
statement ok
drop table t1;
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/handler/create_sql_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ pub async fn handle_create_sql_function(
// Check if the return type mismatches
if e.return_type() != return_type {
return Err(ErrorCode::InvalidInputSyntax(format!(
"return type mismatch detected\nexpected: {}\nactual: {}\nplease adjust your function definition accordingly",
"return type mismatch detected, expected: [{}] actual: [{}], please adjust your function definition accordingly",
return_type,
e.return_type()
))
Expand Down

0 comments on commit b1204f1

Please sign in to comment.