Defining and using external functions#
cmath abs
#
The external
keyword provides a way of calling C functions defined in other
libraries within Python code.
1from rbc.external import external
2cmath_abs = external('int64 abs(int64)')
3
4@heavydb('int64(int64)')
5def apply_abs(x):
6 return cmath_abs(x)
Example SQL Query
1assert apply_abs(-3).execute() == 3
RBC already exposes a small set of C functions from the C stdlib. Check the API reference page for more details.
Using printf
#
1from rbc.externals.stdio import printf
2
3@heavydb('int64(int64)')
4def power_2(x):
5 # This message will show in the heavydb logs
6 printf("input number: %d\n", x)
7 return x * x
Example SQL Query
1assert power_2(3).execute() == 9