Skip to main content

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 29 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')
CONCAT(a, '_', b) CONCAT(CONCAT(a, '_'), b)
CONCAT_WS('-', a, b, c) CONCAT(CONCAT(a, b, '-'), c, '-')
STRPOS(s, 'a') STRPOS(s, 'a') + 1

Some Pinot functions share a name with a standard one but mean something different, and Pinot runs the standard form without an error. The dialect translates them:

  • CONCAT: Pinot's third argument is a separator, so CONCAT(a, '_', b) would join a and '_' with b between them. Pinot also takes at most two values, so longer lists become nested calls.
  • STRPOS: Pinot counts from 0 and returns -1 when the string is absent; the standard counts from 1 and returns 0.
  • SUBSTR: Pinot's SUBSTR(s, start, end) counts from 0 and takes an end index, not a length. Its SUBSTRING is the standard one, so standard SUBSTRING is kept as is.

When it parses Pinot SQL, it keeps Pinot's own forms:

  • DATEDIFF(unit, start, end) keeps all three arguments.
  • CONCAT(a, b, separator) and STRPOS(s, sub) keep Pinot's meaning, so they round-trip unchanged and become the right functions in other dialects.
  • SUBSTR(s, start, end) with literal bounds becomes the equivalent standard SUBSTRING(s, start + 1, end - start).
  • JSON_EXTRACT_SCALAR(json, path, type, default) keeps its type and default.
  • Function names keep the case they were written in, such as ToDateTime and ago.
  • Pinot's types (LONG, STRING, BIG_DECIMAL, BYTES) and LIMIT n OFFSET m are unchanged.

How it is tested

tests/corpus.py is a set of queries against the tables in Pinot's batch QuickStart:

  • 52 Pinot queries that have to round-trip unchanged;
  • 29 queries from Postgres, Trino, MySQL, BigQuery, DuckDB and Snowflake that have to become SQL Pinot accepts;
  • 23 queries whose results are checked against the value the source dialect means, which catches SQL that Pinot runs but reads differently.

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 104 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 or CAST(... AS DATE), so queries that use them fail there whatever dialect wrote them. The rest of the corpus (97 of 104) also passes on the single-stage engine.
  • Percentiles are approximate. APPROX_PERCENTILE maps to Pinot's t-digest estimate. Exact PERCENTILE_CONT is not translated.
  • Pinot-only functions pass through as written. Functions such as ToDateTime, JSON_MATCH or ago survive a Pinot round trip but are not rewritten for other dialects. The same goes for SUBSTR with non-literal bounds and for STRPOS with an occurrence argument.

License

Apache License 2.0. See LICENSE.

Metadata

Release files for sqlglot-pinot 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqlglot-pinot 0.1.3
File Size Uploaded Provenance Actions
sqlglot_pinot-0.1.3.tar.gz 18.4 kB With provenance Details for sqlglot_pinot-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sqlglot-pinot 0.1.3
File Interpreter ABI Platform Actions
sqlglot_pinot-0.1.3-py3-none-any.whl Python 3 none any Details for sqlglot_pinot-0.1.3-py3-none-any.whl

Total release size: 30.3 kB

Release files / sqlglot_pinot-0.1.3.tar.gz

Download URL sqlglot_pinot-0.1.3.tar.gz
Size 18.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4b7fabc0c1345fd3a68c9f3470bfff29183a46015705e7359b41904942cf95fd
BLAKE2b-256 checksum
How to use checksums
41a3b359a45e9b3c23070d3751cef9a838601ad2c0db27d903d12934307c8227
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 30, 2026.

Transparency log

Release files / sqlglot_pinot-0.1.3-py3-none-any.whl

Download URL sqlglot_pinot-0.1.3-py3-none-any.whl
Size 11.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9d33b3055793097e2bdcd5774e33baf66926566b9f5e1ac531536d97e7f13ab1
BLAKE2b-256 checksum
How to use checksums
55ce507f5be109c15cc9f93147d1227ed5b07eee41e021973313462974b26b48
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 30, 2026.

Transparency log

Security for sqlglot-pinot 0.1.3

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.

Select from 2 files

Attestation for sqlglot_pinot-0.1.3.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 30, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page