Open Data Infrastructure
SQLGlot Rewrite Rules for Platform Migration
How SQLGlot rewrite rules make migration behavior testable, reviewable, and visible across SQL dialects.
Platform migration gets messy when SQL changes by folklore. One engineer remembers a dialect quirk, another script fixes one case, and the next incident proves the migration was never actually modeled.
The practical problem
SQLGlot parses, transforms, and transpiles SQL across dialects. That makes it useful for platform migration, especially when teams need to move models, views, or queries across engines without treating every change as a one-off string replacement.
The important word is testable. A migration rewrite should be represented as a rule with examples, expected output, risk notes, and review history. Otherwise, the team has a pile of scripts and no migration contract.
Rewrite rules need evidence
A useful rewrite rule names the source dialect, target dialect, matching pattern, transformation, semantic assumption, and examples that prove the behavior. It should also say what it refuses to rewrite.
That refusal matters. Some SQL differences are syntactic. Others change NULL behavior, timestamp handling, window semantics, identifier case, or optimizer assumptions. A rule that cannot preserve meaning should fail loudly.
Core idea: SQL migration is not only text conversion. It is semantic change control.
The ODI migration pattern
Open Data Infrastructure values engine choice, but engine choice is not free if SQL behavior is trapped in dialect-specific assumptions. SQLGlot can help expose those assumptions so migration work becomes reviewable.
The migration evidence should connect to lineage, model owners, data contracts, and consumer tests. A rewritten query should carry proof that it still answers the same business question.
What breaks first
- A rewrite fixes syntax but changes NULL handling or timestamp meaning.
- One-off migration scripts have no test cases or owner.
- The parser output is trusted without checking semantic behavior against sample data.
- Migration evidence is disconnected from lineage and data product contracts.
Questions to ask
Ask which rewrite rules are automated, which are manual, and which are intentionally forbidden. Ask whether every rule has fixtures. Ask whether rewritten SQL is tested against data product contract checks before promotion.
For adjacent context, read SQLGlot lineage for portable data models, SQLGlot migration in Open Data Infrastructure, and ODI and vendor lock-in.
Sources to start with
These primary sources anchor the technical claims in this guide.
The migration rule should be as reviewable as the query it changes.