Install RBC and get started
You can install RBC using conda
(recommended) or mamba
, which is a faster implementation of conda
. For more information, see the Mamba documentation.
You can also use pip
for package management:
The following assumes that you have an instance of HEAVY.AI running. UDFs and UDTFs are enabled with the flags --enable-runtime-udfs and --enable-table-functions
. For more information on installing HEAVY.AI, see Installation.
To summarize:
To inspect the test database—provided by default—connect another terminal to the database using
The following example shows a simple UDF that converts a numerical temperature from Fahrenheit to Celsius. The code defines the function, registers it, and runs it on the server.
The instance of class RemoteHeavyDB
connects to the HeavyDB instance, and the object it returns can be used to register functions. Then, you define a normal Python function fahrenheit2celsius
. The function is decorated using the instance heavy
of the class RemoteHeavyDB
, and it is provided with the function signature 'double(double)'
. With this modification, the decorated function expects a single argument that is a double-precision floating-point value and also returns a double-precision floating-point value. The syntax is similar to function annotations in C/C++.
After you defined all functions you want to be available on the HeavyDB server, you should register them all at once with heavy.register()
.
fahrenheit2celsius
can now be used in SQL on the HeavyDB server. You can use tools like heavyai or ibis (via the ibis-heavyai backend) to help construct queries from Python. The following example shows a function call from SQL.
The function is then applied element-wise on the column col
of the table my_table
.