UDTF()
; the number of arguments inside represent the total number of input and output columns.out0, out1, ...
. It's possible to use aliases to reference input and output columns in further SQL constructions. For example:int32 (
2**32/2).
fahrenheit2celcius
is defined on a table with one column as input. The final line return 5
means that a table with only 5 rows is returned.size<5
, the output is padded with the value 0. And if size>5
, the function will still iterate on all the rows while just returning the first 5 elements.set_output_row_size
from the module rbc.externals.heavydb
is required. The function must be called before any assignment on output columns.int32
rows—will be loaded whenever the function executes. As with any SQL function, limits on number of rows in tables associated with a UDTF can be set using SQL keywords like LIMIT
or WHERE
.TableFunctionManager
.Cursor
in the UDTF definition as shown above is required.TableFunctionManager
in the signature of a UDTF enables parallel execution of table functions. Without this argument, table functions are executed on a single thread; more importantly, the execution is not thread-safe. To enable threaded execution, the function signature the extra argument for the TableFunctionManager
and the function set_output_row_size
must be called on the manager to ensure thread safety.ColumnList
. In the following example, the mean over each column is returned. It's possible to have multiple ColumnList
parameters. Two helper attributes are available to get the number of rows and column, respectively ColumnList.nrows
and ColumnList.ncols
.[
:]
, [-1]
, [1:6]
, [::2]
).math
module. These functions are defined in rbc.stdlib
, so, to get the full list of supported functions, inspect that module:fahrenheit2celsius_numba
embedded within fahrenheit2celsius
has been decorated with numba.njit
when fahrenheit2celsius
is defined.rbc.external
describes functions known to the server. Those functions on the server can be used when constructing new UDFs or UDTFs by using the function rbc.external.external
. In the following example, log2
is a function which is known on by the database server. To use log2
with a UDF or a UDTF defined using RBC, it needs to be typed using a C-like syntax similar to the one used when decorating functions for RBC.