Introduction to Ibis
Explore large datasets in OmniSci with the full power of SQL, with a pandas-like API, and build a wide variety of visualizations by just writing python code
Introduction to Ibis
Tip: The Ibis open source project documentation is the best place to learn more, and stay up to date
Ibis allows data scientists and researchers to explore data in a variety of remote storage systems, with an API that is inspired by the extremely popular pandas toolkit.
In a nutshell, you can use Ibis to directly interact with OmniSciDB and several other supported SQL systems, by writing high level python code rather than lower-level SQL, making it convenient for Data Scientists working in Python to use familiar tools for increased productivity.
Here is a more detailed summary of what it provides users, taken 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 backends
A major advantage of Ibis is its support for several execution backends including common SQL databases and processing engines. This is powerful because it allows you to author analytical workflows or operations once, that can be run consistently against these backends. It also allows the possibility of creating interesting workflows that can simultaneously materialize data from multiple backends using and combine the resulting outputs in interesting ways.
Notable backends besides OmniSciDB include PySpark, Google BigQuery and PostgreSQL.
Ibis and OmniSciDB
Quick tour of the workflow
Here is a short example of what Ibis does. Inside a notebook cell, you can first connect to an OmniSciDB database instance:
If you're launching JupyterLab from within Immerse, this connection is already set up for you based on your Immerse login and credentials (you don't need to do the above)
Next, let's identify a table and define a simple Ibis expression against it:
This expression is compiled by Ibis into SQL which runs against OmniSciDB:
When executed the above SQL, as expected, counts the rows of the table:
Advanced Tip: If you want to write raw SQL within Ibis, you can still do so! 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 one or supported storage backends to evaluate them and return results. Here is a decidedly more complex Ibis expression and the SQL it generates. Note how you can leverage a full programming language (Python) to assemble complex expressions that cover SQL features like joins, filters and aggregates.
which results in the automatically generated SQL below
The result of the evaluation is by default, a pandas dataframe. This makes it convenient to use Ibis inside other python data analysis workflows.
Tip: While Ibis can output to pandas, remember that the result is first materialized and may be transferred over the network to the client running Ibis (e.g. a Jupyter notebook in a browser on a laptop). It's a bad idea to use it for expressions that try to move a million rows to a browser.
Apache Arrow support
Ibis depends on pymapd as a low-level connector. This means it can leverage some of the key features of pymapd including the ability to output query results to the Arrow format, via the select_ipc
andselect_ipc_gpu
calls.
Building on this capability, the OmniSciDB backend for Ibis can output query results using Apache Arrow, to CPU or GPU memory (the latter, using the cudf dataframe library from Nvidia). This makes it convenient to use with the GPU-based RAPIDS Machine Learning methods. See the RAPIDS example for how you can build a seamless workflow integrating OmniSci and RAPIDs.
Geospatial operations
The OmniSciDB backend for Ibis supports geospatial functions building directly on OmniSciDB's SQL support for these functions. Further, these operations produce geopandas dataframes, allowing for convenient usage in python-based geospatial analytics workflows.
User Defined Functions
Using Ibis, you can create and use User Defined Functions (UDFs) in Python that execute inside OmniSciDB. Of particular note, this UDF framework leverages integration with Numba, a Just-in-Time (JIT) compiler backend for python and produces lower level code to provide a far more performant execution path than execution within Python itself.
It also makes it easy to author UDFs in Python, and have these UDFs then be usable within a SQL workflow.
Additional Resources
Refer to the following sections in the Ibis documentation for how to get started
A great place to start is the Ibis User Guide. In particular the 'Ibis for SQL programmers' section, which shows how Ibis eases workflows involving analytical SQL.
Another good place to start, is the extensive tutorial
Last updated