Search…
Installation
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.
1
conda install -c conda-forge rbc
2
3
# or to install rbc to a new environemnt, run
4
conda create -n rbc -c conda-forge rbc
5
conda activate rbc
6
7
# check if rbc installed succesfully
8
python -c 'import rbc; print(rbc.__version__)'
Copied!
You can also use pip for package management:
1
pip install rbc-project
2
# check if rbc installed succesfully
3
python -c 'import rbc; print(rbc.__version__)'
Copied!

Quick Start

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:
1
conda create -n heavy-ai-env heavydb -c conda-forge
2
conda activate heavy-ai-env
3
mkdir -p data
4
initheavy data -f
5
heavydb --enable-runtime-udfs --enable-table-functions
Copied!
To inspect the test database—provided by default—connect another terminal to the database using
1
heavysql --passwd HyperInteractive
Copied!
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.
1
from rbc.heavydb import RemoteHeavyDB
2
3
heavy = RemoteHeavyDB(
4
user='admin',
5
password='HyperInteractive',
6
host='localhost',
7
port=6274,
8
dbname='heavyai',
9
)
10
11
@heavy('double(double)')
12
def fahrenheit2celsius(f):
13
return (f - 32) * 5 / 9
14
15
print(fahrenheit2celsius(32))
16
# 'fahrenheit2celsius(CAST(32 AS DOUBLE))'
17
18
# other functions?
19
...
20
21
# after defining all functions, they should be registered
22
# to the database
23
heavy.register()
Copied!
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.
1
SELECT fahrenheit2celsius(col) FROM my_table
Copied!
The function is then applied element-wise on the column col of the table my_table.
Export as PDF
Copy link
Contents
Quick Start