Ibis
Explore large datasets in HEAVY.AI with the full power of SQL, with a pandas-like API
The Ibis open source project documentation is the best place to learn more and stay up to date.
Ibis allows you to explore data in a variety of remote storage systems, with an API is inspired by the pandas toolkit.
You can use Ibis to interact directly with HeavyDB and several other supported SQL systems by writing high-level Python code instead of lower-level SQL. Using familiar tools can increase productivity.
Following is summary of what Ibis provides, directly from the Ibis website:
Full coverage of SQL features: You can code in Ibis anything you can implement in a SQL SELECT
Transparent to SQL implementation differences: Write standard code that translate to any SQL syntax
High performance execution: Execute at the speed of your backend, not your local computer
Integration with community data formats and tools (e.g. pandas, Parquet, Avro...)
Ibis support for several execution backends including common SQL databases and processing engines. This allows you to author analytical workflows or operations once and run them consistently against these backends. You can also create complex workflows that can simultaneously materialize data from multiple backends and combine the resulting outputs in various ways.
Supported backends include PySpark, Google BigQuery, and PostgreSQL.
Install the backend ibis-heavyai
You can install ibis-heavyai 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:
Ibis and HeavyDB
This short example demonstrates Ibis. Inside a notebook cell, you can first connect to an HeavyDB database instance:
If you are launching JupyterLab from Immerse, this connection is already set up for you based on your Immerse login and credentials.
This connection object has several utility methods that can come in handy, for listing database objects, creating tables, loading data etc.
Next, let's identify a table and define a simple Ibis expression against it:
This expression is compiled by Ibis into SQL that runs against HeavyDB:
When executed, the above SQL, as expected, counts the rows of the table:
You can also write raw SQL in Ibis. A SQL query can be wrapped as an Ibis expression and composed together with other Ibis expressions.
Ibis offers a powerful way to compose sophisticated analytical expressions, and then leverage the processing power and scale of supported storage backends to evaluate them and return results. The following shows a more complex Ibis expression and the SQL it generates. You can leverage a full programming language (Python) to assemble complex expressions that cover SQL features like joins, filters, and aggregates.
This results in automatically generated SQL:
The result of the evaluation is by default a pandas dataframe, making it convenient to use Ibis inside other Python data analysis workflows.
api
om2
dp2
0
4201335379
3.944927
2016-11-01
1
4201335467
4.125253
2017-12-01
2
4201334998
3.822887
2014-09-01
3
4201334930
3.698709
2014-05-01
4
4201334917
4.353243
2014-06-01
5
4201334812
4.127299
2014-03-01
6
4201334947
3.715502
2014-06-01
7
4201334978
3.822887
2014-09-01
8
4201335112
4.010766
2015-01-01
9
4201334329
3.721068
2015-07-01
Although Ibis can output to pandas, the result is first materialized and could be transferred over the network to the client running Ibis (such as a Jupyter notebook in a browser on a laptop). Avoid using it for expressions that try to move a million rows to a browser.
Apache Arrow Support
Ibis depends on heavyai as a low-level connector. It can leverage some of the key features of pyomnisci, including output of query results to the Arrow format via the select_ipc
andselect_ipc_gpu
calls.
Building on this capability, the HeavyDB backend for Ibis can output query results using Apache Arrow to CPU or GPU memory (the latter by using the cudf dataframe library from NVIDIA). This makes it convenient to use with the GPU-based RAPIDS machine learning methods. Output to cudf is as simple as passing an extra couple of parameters to the execute
method in ibis, for example, as follows
See the RAPIDS example for how you can build a workflow integrating HEAVY.AI and RAPIDs.
RAPIDs is currently usable only with supported Nvidia GPUs and requires CUDA
Geospatial Operations
The HeavyDB backend for Ibis supports geospatial functions building directly on HeavyDB SQL support for these functions. These operations produce geopandas dataframes, allowing for usage in Python-based geospatial analytics workflows.
Here is an example of how a table that has geospatial data in HEAVY.AI, can output directly to a geopandas dataframe.
User-Defined Functions
Using Ibis, you can create and use user-defined functions (UDFs) in Python that execute inside HeavyDB. This UDF framework leverages integration with Numba, a Just-in-Time (JIT) compiler backend for python, and produces lower-level code for a more performant execution path than within Python itself.
It also makes it easy to author UDFs in Python, and then make the UDFs usable in a SQL workflow.
Additional Resources
See the following Ibis documentation to get started:
The Ibis User Guide---in particular, the Ibis for SQL programmers section, which shows how Ibis simplifies workflows involving analytical SQL.
The extensive tutorials.