Skip to content

Commit f92d7f6

Browse files
feat(udf): support user-defined table function (UDTF) (risingwavelabs#8255)
Signed-off-by: Runji Wang <[email protected]> Co-authored-by: xxchan <[email protected]>
1 parent 61191c2 commit f92d7f6

File tree

24 files changed

+676
-63
lines changed

24 files changed

+676
-63
lines changed

dashboard/proto/gen/catalog.ts

Lines changed: 113 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dashboard/proto/gen/expr.ts

Lines changed: 66 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e_test/udf/python.slt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ create function gcd(int, int, int) returns int language python as gcd3 using lin
2424
statement error exists
2525
create function gcd(int, int) returns int language python as gcd using link 'http://localhost:8815';
2626

27+
# Create a table function.
28+
statement ok
29+
create function series(int) returns table (x int) language python as series using link 'http://localhost:8815';
30+
31+
statement ok
32+
create function series2(int) returns table (x int, s varchar) language python as series2 using link 'http://localhost:8815';
33+
2734
query I
2835
select int_42();
2936
----
@@ -39,6 +46,26 @@ select gcd(25, 15, 3);
3946
----
4047
1
4148

49+
query I
50+
select series(5);
51+
----
52+
0
53+
1
54+
2
55+
3
56+
4
57+
58+
# FIXME: support table function with multiple columns
59+
# query IT
60+
# select series2(5);
61+
# ----
62+
# (0,0)
63+
# (1,1)
64+
# (2,2)
65+
# (3,3)
66+
# (4,4)
67+
68+
4269
# TODO: drop function without arguments
4370

4471
# # Drop a function but ambiguous.

e2e_test/udf/test.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import sys
2+
from typing import Iterator
23
sys.path.append('src/udf/python') # noqa
34

4-
from risingwave.udf import udf, UdfServer
5+
from risingwave.udf import udf, udtf, UdfServer
56

67

78
@udf(input_types=[], result_type='INT')
@@ -21,9 +22,23 @@ def gcd3(x: int, y: int, z: int) -> int:
2122
return gcd(gcd(x, y), z)
2223

2324

25+
@udtf(input_types='INT', result_types='INT')
26+
def series(n: int) -> Iterator[int]:
27+
for i in range(n):
28+
yield i
29+
30+
31+
@udtf(input_types=['INT'], result_types=['INT', 'VARCHAR'])
32+
def series2(n: int) -> Iterator[tuple[int, str]]:
33+
for i in range(n):
34+
yield i, str(i)
35+
36+
2437
if __name__ == '__main__':
2538
server = UdfServer()
2639
server.add_function(int_42)
2740
server.add_function(gcd)
2841
server.add_function(gcd3)
42+
server.add_function(series)
43+
server.add_function(series2)
2944
server.serve()

0 commit comments

Comments
 (0)