SQL Parser¶
Core SQL parser powered by sqlglot. Extracts nodes, edges, column usage, and column lineage from SQL statements.
SqlParser
¶
SqlParser(dialect=None)
Parses SQL files into nodes, edges, column usage, and column lineage using sqlglot.
Handles multi-statement files, CTE extraction, column-level scope analysis, transform detection, and end-to-end column lineage tracing. Dialect-aware identifier normalisation ensures consistent casing across Postgres, Snowflake, DuckDB, and other engines.
Initialise with an optional SQL dialect.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dialect
|
str | None
|
sqlglot dialect string (e.g., 'postgres', 'mysql', 'duckdb'). None for auto-detection. |
None
|
Source code in src/sqlprism/languages/sql.py
46 47 48 49 50 51 52 53 | |
parse
¶
parse(file_path, file_content, schema=None)
Parse a SQL file into nodes, edges, column usage, and column lineage.
Handles multiple statements per file. Each statement is parsed independently. Errors in one statement don't prevent parsing others.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to the SQL file (used for naming nodes). |
required |
file_content
|
str
|
Raw SQL content. |
required |
schema
|
dict | None
|
Optional schema catalog |
None
|
Returns:
| Type | Description |
|---|---|
ParseResult
|
A |
ParseResult
|
column usage records, column lineage chains, and any |
ParseResult
|
non-fatal parse errors. |
Source code in src/sqlprism/languages/sql.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |