Repository navigation
sqlglot Bridge
The bridge is an optional second printer: it converts FactLang's internal SQL tree into a sqlglot expression and asks sqlglot to print it for any dialect it knows. It reaches the long tail (Presto, Athena, Hive, StarRocks, Doris, Teradata and more) and is always labelled
best_effort. It lives infactlang/sql/sqlglot_bridge.py, imported lazily, and needspip install factlang[sqlglot].
Native profiles are the verified path, but nobody can hand-write a profile for every warehouse. sqlglot already knows dozens. The owner chose both: native profiles as the core, sqlglot as an extra.
A translator dependency would sit exactly where a fact checker cannot be wrong. If a translation bug turned COUNT(DISTINCT x) into something subtly different, a verdict would be silently wrong. So the bridge is optional, labelled best effort on every outcome, and not used when a native profile exists (unless you force it).
- The primitive is lowered to the internal SQL tree, the same one the native printer uses.
- The bridge builds a sqlglot expression tree from that tree.
- sqlglot prints it with
.sql(dialect=name). - Parameters become placeholders mapped to the target parameter style.
Because both printers share step 1, they cannot disagree on meaning.
Tests use the bridge to parse native SQL back in each dialect (the native tier is checked this way), and on DuckDB and Postgres they run both paths and require equal results. Checker(..., prefer="sqlglot") forces the bridge.
- Tier is always
best_effort. - Sampling:
systemandbernoulliwork where sqlglot has aTABLESAMPLEform;keyhashonly for the dialects FactLang has a hash expression for; anything else is FL506.
FactLang
Using it
Components
Extending
Help