Using templates#

Templates are generic types used in the decorator @heavydb. Templating allows the target function to accept different data types for its arguments.

Assuming you already have a connection to the HeavyDB server:

from test_templates of rbc/tests/heavydb/test_howtos.py#
1@heavydb('Z(T, Z)', T=['int32', 'float'], Z=['int64', 'double'])
2def add(a, b):
3    return a + b

In the case above, the template arguments T and Z, are specified within the decorator, indicating the valid data types that can be used for the add function.

Example SQL Query
from test_templates of rbc/tests/heavydb/test_howtos.py#
1if heavydb.version[:2] >= (6, 2):
2    assert heavydb.function_names(runtime_only=True) == ['add']
3    assert len(heavydb.function_details('add')) == 4
4assert add(2, 3).execute() == 5