Skip to main content

trino-sql-validator

Fast Trino SQL syntax validator — a Python library whose core is written in Rust and compiled to a native extension via PyO3 + maturin.

Installable from PyPI:

pip install trino-sql-validator

Quickstart

from trino_sql_validator import validate, validate_file

# A string with one or many statements
result = validate("SELECT 1; SELECT * FROM t WHERE a > 0;")
assert result.valid
assert result.statement_count == 2

# Invalid SQL returns a value, never raises
result = validate("SELECT * FORM t")
assert not result.valid
print(result.error)          # e.g. "Expected: end of statement, found: FORM at line 1, column 10"
print(result.error.line)     # 1

# Validate a file
result = validate_file("queries.sql", dialect="trino")

Invalid SQL (and files containing it) is returned as a ValidationResult; it is not raised as an exception. Only genuine misuse (unknown dialect, unreadable file) raises.

Catalog warnings (functions and data types)

For dialect="trino", validate() also checks that every function called and every data type used in the SQL exists in the documented Trino catalog. Unknown names are reported as non-fatal warnings — valid stays True because syntax is fine:

result = validate("SELECT marh(1.5)")       # round() misspelled
assert result.valid
print(result.warnings)                      # (FunctionWarning(name='marh', line=1, column=8),)
print(result.unknown_functions)             # ['marh']

result = validate("CREATE TABLE t (a bignum, b bigint)")  # bigint vs bignum
print(result.warnings[0])                   # TypeWarning(name='bignum', line=1, column=19)
print(result.unknown_types)                 # ['bignum']

The catalogs are auto-generated from the Trino docs and only check name existence, not argument counts, precision/scale, or semantic correctness. hive/generic dialects skip these checks. False positives are possible if a deployed Trino adds plugin functions/types beyond the docs.

dbt and Jinja templates

Jinja/dbt SQL is supported by default. validate() and validate_file() use jinja="auto" to mask Jinja expressions, statements, and comments before parsing while preserving line numbers and file structure. This supports constructs such as {{ ref("orders") }} and {{ var("catalog") }} without requiring a dbt installation or project context. Use jinja="mask" as an explicit spelling of the same mode.

Use jinja="reject" to pass the original template directly to the SQL parser. Masking cannot determine SQL generated by control-flow blocks, macros, or adapter semantics; render those cases with dbt and validate the rendered SQL for complete coverage.

Dialects

  • "trino" (default) — Trino-flavored with a custom override tuned for current Trino syntax, including Iceberg branches/time travel, complex nested types, routines, table functions, SQL/JSON, and Trino-specific DDL.
  • "hive" and "generic" — offered as permissive alternates.

Known limitations

sqlparser-rs (the parser we use) performs syntax validation, not semantic analysis. It may accept SQL that Trino would reject at analysis time (unknown columns/tables, duplicate columns), and it can reject exotic Trino-specific DDL. The validator has targeted compatibility parsing for documented Trino syntax, including nested ROW/ARRAY/MAP types, but it does not replace Trino's semantic analyzer. For the overwhelming majority of SELECT/DDL statements the results are accurate. See plan/roadmap.md for the path toward stricter Trino fidelity.

Parser fidelity is checked reproducibly against direct-string cases extracted from Apache Trino's parser tests. The pinned Trino 483 gate currently accepts 456/456 extracted statements and 68/68 extracted types, and rejects 23/23 direct negative statements. These figures describe the extractable syntax subset, not the full Trino semantic analyzer or connector runtime behavior.

Development

See AGENTS.md for setup, internal conventions, and release steps. Key commands:

python3 -m venv .venv && source .venv/bin/activate
pip install -U pip maturin && pip install -e ".[dev]"
maturin develop          # build + install native ext into the venv
cargo test               # Rust tests
pytest -q                # Python tests
cargo fmt --check        # formatting
cargo clippy --all-targets -- -D warnings

License

MIT

Release files for trino-sql-validator 0.13.0

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

Source distribution (sdist)

Source distribution for trino-sql-validator 0.13.0
File Size Uploaded
trino_sql_validator-0.13.0.tar.gz 124.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for trino-sql-validator 0.13.0
File
trino_sql_validator-0.13.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
trino_sql_validator-0.13.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
trino_sql_validator-0.13.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
trino_sql_validator-0.13.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
trino_sql_validator-0.13.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 11.3 MB

Release files / trino_sql_validator-0.13.0.tar.gz

Download URL trino_sql_validator-0.13.0.tar.gz
Size 124.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d4f8e4f663f3d1bf4bbebb8ed765424ab7ee896f2c200e450eca26d6d4d9879d
BLAKE2b-256 checksum
How to use checksums
73aeeb419d8510444045d7c07da57bcf4f0c06e626ade9d9786da75589785abe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / trino_sql_validator-0.13.0-cp310-abi3-win_amd64.whl

Download URL trino_sql_validator-0.13.0-cp310-abi3-win_amd64.whl
Size 2.3 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
5edd240b3e5f65d3de889e8089bd32675647ad7d45bd67c84478b9e73446089e
BLAKE2b-256 checksum
How to use checksums
0c2b49ff5d85cc3a766358624e352d55224f8e4464b863002f5393c3699a7adb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / trino_sql_validator-0.13.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL trino_sql_validator-0.13.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.3 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
de12b8996b7af37a9c1df396e4521f3b7438b86d97418df5030ddf0a86bd7c94
BLAKE2b-256 checksum
How to use checksums
fc739c011859658f3afa967d331fde78630fc23dc6ccee26f7085b6763660c0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / trino_sql_validator-0.13.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL trino_sql_validator-0.13.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 2.2 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
65c183d53d7e90a6af758c15113e0dedf25f0bbabf73b2250c7cca036853c3ea
BLAKE2b-256 checksum
How to use checksums
e7fd3edf1e007eab4a8736d890b876a746dd86593696c371f2bb7281e321a483
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / trino_sql_validator-0.13.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL trino_sql_validator-0.13.0-cp310-abi3-macosx_11_0_arm64.whl
Size 2.1 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
7611164b5cd04010d53f04d97d59dd7ce32cececa9bf0e20bdb70b15b78b47a6
BLAKE2b-256 checksum
How to use checksums
0b79952b7c68292049c137661ee3939965a312c9fa86f087b1109ee4cdd3cbfd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / trino_sql_validator-0.13.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL trino_sql_validator-0.13.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 2.2 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
454a309558ba2710c928444ffc0b2224db850421e0202a99df8266009c556a53
BLAKE2b-256 checksum
How to use checksums
5a34a139e7d3d1a6b2aee722983ee73671ec0382bdceb73fc12bba75084bec4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

0.17.0

6 release files

0.16.0

6 release files

0.15.0

6 release files

0.14.0

6 release files

This release

0.13.0 This release

6 release files

0.12.0

6 release files

0.11.0

6 release files

0.10.0

6 release files

0.9.0

6 release files

0.8.0

6 release files

0.7.0

6 release files

0.6.0

6 release files

0.5.0

6 release files

0.4.0

6 release files

0.2.0

6 release files

0.1.0

6 release files

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