User Defined Functions (UDFs)#

Basics#

UDFs are functions that operate at row-level. That is, they receive as input a single row at a time.

from test_udf of rbc/tests/heavydb/test_howtos.py#
1@heavydb('int64(int64)')
2def incr(a):
3    return a + 1
Example SQL Query
from test_column of rbc/tests/heavydb/test_howtos.py#
1_, result = heavydb.sql_execute('SELECT incr(3)')
2assert list(result) == [(4,)]

Multiple signatures#

Defining UDFs with multiple signatures

from test_udf of rbc/tests/heavydb/test_howtos.py#
1@heavydb('int64(int64, int64)', 'float64(float64, float64)')
2def multiply(a, b):
3    return a * b
Example SQL Query
from test_column of rbc/tests/heavydb/test_howtos.py#
1_, result = heavydb.sql_execute('SELECT multiply(3.0, 2.0)')
2assert list(result) == [(6.0,)]