How wahid989/sqlglot works
SQLGlot is a Python SQL parser, transpiler, optimizer, and lightweight execution engine. The principal workflow accepts SQL plus an optional source dialect, tokenizes and parses it into an expression tree, then generates SQL in a target dialect. Separate capabilities include query analysis, planning and execution, AST comparison, lineage, and JSONPath. Edges are limited to relationships visible in excerpts, SOURCE INDEX references, or README statements; several feature implementations are unsampled, so their internal connections are not asserted.
Main entry points: __init__.py Public API · dialect.py Dialect registry · parser.py SQL parser · optimizer.py Query optimizer
Components 19
SQL Parsing
- Public API
sqlglot/__init__.py - Tokenizer
sqlglot/tokens.py - Dialect registry
sqlglot/dialects/dialect.py - SQL parser
sqlglot/parser.py - Dialect grammars
sqlglot/parsers
Expression Model
- Expression tree
sqlglot/expressions/core.py - Query expressions
sqlglot/expressions/query.py
SQL Analysis & Output
- Query optimizer
sqlglot/optimizer/optimizer.py - Scope analysis
sqlglot/optimizer/scope.py - Type annotation
sqlglot/optimizer/annotate_types.py - Schema metadata
sqlglot/schema.py - SQL generator
sqlglot/generator.py
Additional Capabilities
- Query planner
sqlglot/planner.py - Python executor
sqlglot/executor/python.py - Query lineage
sqlglot/lineage.py - AST diff
sqlglot/diff.py - JSONPath
sqlglot/jsonpath.py
Other components
- SQL caller
- External SQL engine
Connections 23
- SQL caller → Public API: submits SQL
README.md - Public API → Dialect registry: selects dialect
sqlglot/__init__.py - Public API → Tokenizer: tokenizes
sqlglot/__init__.py - Public API → SQL parser: parses SQL
sqlglot/__init__.py - Dialect registry → Tokenizer: configures tokenizer
sqlglot/dialects/dialect.py - Dialect registry → SQL parser: configures parser
sqlglot/dialects/dialect.py - Dialect registry → SQL generator: configures generator
sqlglot/dialects/dialect.py - SQL parser → Expression tree: builds nodes
sqlglot/parser.py - Expression tree → Query expressions: extends query model
sqlglot/expressions/query.py - Public API → SQL generator: generates SQL
README.md - Public API → Query optimizer: optimizes queries
README.md - Query optimizer → Scope analysis: analyzes scopes
- Query optimizer → Type annotation: annotates types
- Type annotation → Scope analysis: reads scopes
sqlglot/optimizer/annotate_types.py - Type annotation → Schema metadata: reads schema
sqlglot/optimizer/annotate_types.py - Public API → Query planner: plans SQL
README.md - Query planner → Python executor: feeds plan
sqlglot/executor/python.py - Python executor → External SQL engine: executes locally
README.md - Public API → Query lineage: analyzes lineage
README.md - Public API → AST diff: compares trees
README.md - Public API → JSONPath: queries JSONPath
sqlglot/dialects/dialect.py - Dialect grammars → SQL parser: extends dialect parsing
sqlglot/parsers/bigquery.py - Dialect grammars → SQL generator: extends dialect output