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

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.2
File Size Uploaded Provenance Actions
sqlglot_pinot-0.1.2.tar.gz 17.6 kB With provenance Details for sqlglot_pinot-0.1.2.tar.gz

Built distribution (wheel)

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

Total release size: 29.4 kB

Release files / sqlglot_pinot-0.1.2.tar.gz

Download URL sqlglot_pinot-0.1.2.tar.gz
Size 17.6 kB
Tags Source
SHA-256 checksum
How to use checksums
1b15214ecd419b867374c9a6367304109d41d967cead46f2b05a51798d1ba055
BLAKE2b-256 checksum
How to use checksums
9e0624257891a8197ac0ba80f240d4ecb8376c9ae9f7fad08d344a2665a06d8b
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 log

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

Download URL sqlglot_pinot-0.1.2-py3-none-any.whl
Size 11.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c5f0d7c14a0e647975866b25682ca17277c7bd3e692c28a5cb0e84c634b37954
BLAKE2b-256 checksum
How to use checksums
57a49a4f8fcbfdf986e07d35cd2eb5ee095cdc70bf4c3368826e968d9d766ee0
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 log

Security for sqlglot-pinot 0.1.2

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