Skip to content

Commit

Permalink
refactor(test): assemble unimplemented tests together & add future ro…
Browse files Browse the repository at this point in the history
…admap for sql udf (#15039)
  • Loading branch information
xzhseh authored Feb 7, 2024
1 parent 948cc92 commit 6fc8fad
Showing 1 changed file with 127 additions and 11 deletions.
138 changes: 127 additions & 11 deletions e2e_test/udf/sql_udf.slt
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ select type_match(114514);
----
$1 + 114514 + $1

#################################################################################
# Invalid definition (and maybe not yet supported features 🤪) / use case tests #
#################################################################################
##################################################
# Invalid definition tests when creating sql udf #
##################################################

# Named sql udf with invalid parameter in body definition
# Will be rejected at creation time
Expand Down Expand Up @@ -306,14 +306,6 @@ create function fib(INT) returns int
else fib($1 - 1) + fib($1 - 2)
end;';

# The execution will eventually exceed the pre-defined max stack depth
# statement error function fib calling stack depth limit exceeded
# select fib(100);

# Currently create a materialized view with a recursive sql udf will be rejected
# statement error function fib calling stack depth limit exceeded
# create materialized view foo_mv as select fib(100);

# Calling a non-existent function
statement error failed to conduct semantic check, please see if you are calling non-existent functions
create function non_exist(INT) returns int language sql as 'select yo(114514)';
Expand All @@ -326,6 +318,20 @@ create function type_mismatch(INT) returns varchar language sql as 'select $1 +
statement error Expected an expression:, found: EOF at the end
create function add_error(INT, INT) returns int language sql as $$select $1 + $2 +$$;

######################################################################
# Not yet supported features 🤪 (and potential basic use case tests) #
######################################################################

# 1. Recursion Support for SQL UDF

# The execution will eventually exceed the pre-defined max stack depth
# statement error function fib calling stack depth limit exceeded
# select fib(100);

# Currently create a materialized view with a recursive sql udf will be rejected
# statement error function fib calling stack depth limit exceeded
# create materialized view foo_mv as select fib(100);

# Rejected deep calling stack
# statement error function recursive calling stack depth limit exceeded
# select recursive(1, 1);
Expand All @@ -342,6 +348,116 @@ create function add_error(INT, INT) returns int language sql as $$select $1 + $2
# statement error function fib calling stack depth limit exceeded
# create materialized view bar_mv as select fib(c1) from t1;

# 2. Select from table inside SQL UDF (potential concerns: naming conflict)

# statment ok
# create funciton from_table_single_row() returns int language sql as 'select c1 from t1';

# Do NOT need explicit `select ... from ...`
# query I
# select from_table_single_row();
# ----
# 1

# statement ok
# create function from_table_single_row_1() returns int language sql as 'select c1 from t1 order by c1 desc';

# Need explict `select ... from ...`
# query I
# select * from from_table_single_row_1();
# ----
# 5

# Should add parser support
# statement ok
# create function from_table_multiple_rows() returns setof int language sql as 'select c1 from t1';

# P.S. postgres shadows the `c1` parameter by the actual column `c1` to resolve the naming conflict
# statement ok
# create function from_table_conflict(c1 INT) returns int language sql as 'select c1 from t1';

# 3. Output multiple columns / expressions from a single SQL UDF

# Parser support is needed
# statement ok
# create function out_parameters_without_name(out INT, out INT) language sql as 'select 1919810, 114514';

# query II
# select out_parameters_without_name();
# ----
# 1919810 114514

# query II
# select * out_parameters_without_name();
# ----
# 1919810 114514

# statement error non-existent column
# select a, b from out_parameters_without_name();
# ----
# 1919810 114514

# statement ok
# create function out_parameters_with_name(out a INT, out b INT) language sql as 'select 1919810, 114514';

# query II
# select out_parameters_with_name();
# ----
# 1919810 114514

# query II
# select a, b from out_parameters_with_name();
# ----
# 1919810 114514

# statement ok
# create function multiple_cols() returns setof record as 'select c1, c2, c3 from t2' language sql;

# query III
# select * from multiple_cols() as t(c1 INT, c2 FLOAT, c3 INT);
# ----
# corresponding results
# may need to order the sequence

# 4. Polymorphic arguments

# statement ok
# create function is_greater(anyelement, anyelement) returns boolean language sql as 'select $1 > $2';

# query I
# select is_greater(1, 2);
# ----
# f

# query I
# select is_greater(3.14, 2.95);
# ----
# t

# 5. Overloading functions

# statement ok
# create function overload(c1 INT) returns int language sql as 'select c1';

# statement ok
# create function overload(c1 VARCHAR) returns varchar language sql as 'select c1';

# query I
# select overload(114514), overload('114514');
# ----
# 114514 114514

# statement error naming conflict with first overload
# create function overload(c1 INT, out VARCHAR)

# This definition will cause ambiguity with the second overload during runtime if `c2` is not specified
# statement ok
# create function overload(c1 VARCHAR, c2 VARCHAR default '114514', out VARCHAR, out VARCHAR) language sql as 'select c1, c2';

# statement error can not choose a best candidate function, need explicit type cast
# query TT
# select overload('114514');

##################################################
# Clean up the funtions / mock tables at the end #
##################################################
Expand Down

0 comments on commit 6fc8fad

Please sign in to comment.