sqlglot-pinot
An Apache Pinot dialect for sqlglot, packaged as a sqlglot dialect plugin.
With it, sqlglot can turn SQL written for another engine into SQL Pinot runs, turn Pinot SQL into SQL for other engines, and parse and regenerate Pinot SQL without breaking it.
import sqlglot
sqlglot.transpile("SELECT STDDEV(x), APPROX_DISTINCT(y) FROM t", read="trino", write="pinot")
# ['SELECT STDDEV_SAMP(x), DISTINCTCOUNTHLL(y) FROM t']
sqlglot.transpile(
"SELECT DATEDIFF('DAY', a, b), PERCENTILETDIGEST(x, 90) FROM t", read="pinot", write="bigquery"
)
# ['SELECT DATE_DIFF(b, a, DAY), APPROX_QUANTILES(x, 10)[9] FROM t']
Install
pip install sqlglot-pinot
Installing the package registers the dialect with sqlglot under the name
pinot; there is nothing to import. You can also use the class directly:
from sqlglot_pinot import Pinot
Requires Python 3.10+ and sqlglot 30 or later.
What it handles
The dialect builds on sqlglot's Trino dialect. Pinot's multi-stage engine is based on Apache Calcite and shares Trino's quoting rules and most of its SQL, so only the differences are overridden.
| SQL from other dialects | Pinot SQL generated |
|---|---|
STDDEV(x), VARIANCE(x) |
STDDEV_SAMP(x), VAR_SAMP(x) |
APPROX_DISTINCT(x), APPROX_COUNT_DISTINCT(x) |
DISTINCTCOUNTHLL(x) |
APPROX_PERCENTILE(x, 0.9) |
PERCENTILETDIGEST(x, 90) |
CURRENT_TIMESTAMP |
NOW() |
DATE_DIFF('day', a, b), DATEDIFF(b, a) |
DATEDIFF('DAY', a, b) |
CAST(x AS VARCHAR(10)), BIGINT, DECIMAL(10, 2) |
CAST(x AS STRING), LONG, BIG_DECIMAL |
TIMESTAMP WITH TIME ZONE |
TIMESTAMP (Pinot stores UTC milliseconds) |
`col` (MySQL) |
"col" |
j ->> 'a' |
JSON_EXTRACT_SCALAR(j, '$.a', 'STRING') |
When it parses Pinot SQL, it keeps Pinot's own forms:
DATEDIFF(unit, start, end)keeps all three arguments.JSON_EXTRACT_SCALAR(json, path, type, default)keeps its type and default.- Function names keep the case they were written in, such as
ToDateTimeandago. - Pinot's types (
LONG,STRING,BIG_DECIMAL,BYTES) andLIMIT n OFFSET mare unchanged.
How it is tested
tests/corpus.py is a set of queries against the tables in
Pinot's batch QuickStart. It has 50 Pinot queries that have to round-trip
unchanged, and 29 queries from Postgres, Trino, MySQL, BigQuery, DuckDB and
Snowflake that have to become SQL Pinot accepts.
The unit tests check the generated SQL text. The live tests send every query to
a real Pinot broker, and CI runs them against Pinot 1.4.0, 1.5.1 and 1.6.0. All
79 pass on each of those releases with the multi-stage engine.
scripts/check_versions.sh 1.6.0 1.5.1 runs the same check against fresh
QuickStart containers on both engines.
Run them yourself:
docker run -p 8000:8000 -p 9000:9000 apachepinot/pinot:1.6.0 QuickStart -type batch
PINOT_BROKER_URL=http://127.0.0.1:8000 pytest
Limitations
- The target is the multi-stage engine. Pinot's single-stage engine has no
joins, CTEs, window functions,
||, interval arithmetic orCAST(... AS DATE), so queries that use them fail there whatever dialect wrote them. The rest of the corpus (73 of 79) also passes on the single-stage engine. - Percentiles are approximate.
APPROX_PERCENTILEmaps to Pinot's t-digest estimate. ExactPERCENTILE_CONTis not translated. - Pinot-only functions pass through as written. Functions such as
ToDateTime,JSON_MATCHoragosurvive a Pinot round trip but are not rewritten for other dialects.
License
Apache License 2.0. See LICENSE.
Metadata
Release files for sqlglot-pinot 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sqlglot_pinot-0.1.0.tar.gz | 14.6 kB | With provenance | Details for sqlglot_pinot-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sqlglot_pinot-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for sqlglot_pinot-0.1.0-py3-none-any.whl |
Total release size: 24.7 kB
Release files / sqlglot_pinot-0.1.0.tar.gz
| Download URL | sqlglot_pinot-0.1.0.tar.gz |
|---|---|
| Size | 14.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d99d7082578eeefb3e949809b709ca0852f17b69122eab7bba645437f399e9b5
|
|
BLAKE2b-256 checksum How to use checksums |
47b81856387a2e3369a7413b68b31e0937938464cf2640e658919ec697aab802
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logRelease files / sqlglot_pinot-0.1.0-py3-none-any.whl
| Download URL | sqlglot_pinot-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c9d204634b8eb79a8ab02cd38da9e1f6aee6160edf0e4fcbdc1791307e33c202
|
|
BLAKE2b-256 checksum How to use checksums |
5a9300ccba0b782f50f22fb95808195afa3cc92323b799a1f5072a2d8f88c9d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logSecurity for sqlglot-pinot 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for sqlglot_pinot-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.