User Defined Table Functions (UDTFs)#

UDTFs are functions that operate on a column-level basis. In simpler terms, UDTFs take a set of columns as input and return a set of columns as output.

from test_udtf of rbc/tests/heavydb/test_howtos.py#
1@heavydb('int32(TableFunctionManager, Column<int64>, OutputColumn<int64>)')
2def my_copy(mgr, inp, out):
3    size = len(inp)
4    mgr.set_output_row_size(size)
5    for i in range(size):
6        out[i] = inp[i]
7    return size
Example SQL Query
from test_udtf of rbc/tests/heavydb/test_howtos.py#
1query = '''
2    SELECT * FROM TABLE(my_copy(
3        cursor(SELECT * FROM TABLE(generate_series(1, 5, 1)))
4    ));
5'''
6_, result = heavydb.sql_execute(query)
7assert list(result) == [(1,), (2,), (3,), (4,), (5,)]