Query Pinot from Jupyter with JupySQL
Query Apache Pinot from a Jupyter notebook using JupySQL magics, plot results, and keep them as pandas DataFrames for EDA.
This tutorial shows how to use JupySQL and the pinotdb Python client to query Apache Pinot from a Jupyter notebook: SQL magics, plots, and DataFrames for EDA.
A runnable notebook lives in the Pinot source tree:
Prerequisites
Python 3.10+
A running Pinot batch quickstart (loads the
baseballStatstable)Jupyter, JupySQL, pinotdb, pandas, and matplotlib
The batch and Docker quickstarts expose the broker SQL API on port 8000 and the controller UI on port 9000. Do not use port 8099 unless you started a cluster that binds the broker there.
Start Pinot (Docker)
docker run --name pinot-quickstart \
-p 2123:2123 -p 9000:9000 -p 8000:8000 \
-d apachepinot/pinot:latest QuickStart -type batchWait until http://localhost:9000 is up.
Start Pinot (local build)
From an apache/pinot checkout after a binary build:
Install Python packages
Or, from the Pinot repo:
Connect from the notebook
JupySQL talks to Pinot through SQLAlchemy and pinotdb. Create an engine and pass it to %sql (more reliable than embedding a non-standard URL in the magic):
Enable the multi-stage query engine on the connection. JupySQL %sqlplot rewrites plots as WITH ... queries, which the single-stage engine rejects.
The URL shape is:
Query with SQL magics
%%sql sends the statement to the broker POST /query/sql endpoint.
Scan a few rows:
Aggregate with GROUP BY / ORDER BY:
Plot from SQL
With SqlMagic.autopandas = True, a %sql assignment is a pandas DataFrame:
You can also save a result and use JupySQL's %sqlplot:
Use Pinot results in EDA or modeling
Keep the DataFrame and continue in Python (further EDA, sklearn, and so on). This tutorial stops at the DataFrame — it does not train a model.
Next steps
Full notebook: pinot_jupysql_eda.ipynb
Last updated
Was this helpful?

