Repository navigation
Commit bfaff24
authored
perf: evaluate built-in rules over Polyglot query facts and drop sqlparser (#1143)
* feat(analysis): expose the mapped dialect normalization of analysis SQL
Rules need analysis's Snowflake variant normalization together with the
character map back to the authored SQL, so positions survive the rewrite.
* perf(rules): evaluate built-in model rules over Polyglot query facts
Built-in model and SQL-test rules re-parsed every model with sqlparser.
They now read compact facts from one Polyglot parse per stubbed query
shape: dependency calls are stubbed by occurrence, shapes are shared by
the rules workers when their stubbed SQL is byte-identical, and positions
map back to each model's own SQL.
Models sqlparser rejected but Polyglot parses are now evaluated;
SQBRDECLARATION101/102 quote the comparison's source text and follow its
source position. Unparseable SQL keeps the unevaluated result with
Polyglot's error.
* build: drop sqlparser from the workspace
The rules quote policy is a static dialect table, so no crate needs
sqlparser any more.
* fix(rules): honour dialect comment syntax when stubbing query shapes
The stub scanner only knew -- and /* */ comments, so a Snowflake // or a
Snowflake/BigQuery # comment could hold a phantom __ref call, or an
apostrophe in it could open a fake string that swallowed real calls.
Scan with the comment and quoting syntax the rules parser used per
dialect, and blank comments before normalization and parsing.
* fix(rules): match sqlparser literal, function-call, TOP and import-star facts
- SQBRDECLARATION101 compares each string literal's own source text with
the authored SQL and covers double-quoted, triple-quoted, escape and
Unicode strings again.
- SQBRTEST203 no longer treats a parameterized cast type such as
DECIMAL(18, 2) as a function call.
- A T-SQL TOP (n), TOP n PERCENT or WITH TIES clause is not projection.
- Stars in dependency import CTEs are exempt from SQBRMODEL102 by CTE
classification, not by having a recovered source position.
* fix(rules): anchor FROM-first stars on their FROM keyword
A DuckDB FROM-first query has an implicit star but no SELECT token, so
its star finding fell back to 1:1. Anchor that star on the FROM keyword.
A SELECT whose only located part is an unaliased subquery is now matched
to its own SELECT keyword through the subquery's opening parenthesis, so
its star keeps its source position too.
* fix(rules): treat CONVERT and TRY_CONVERT type arguments as types
SQBRTEST203 counted the leading parameterized type of a T-SQL
CONVERT(VARCHAR(10), x) or TRY_CONVERT(DECIMAL(18, 2), x) as a function
call, so an empty SQL Server mock or bare existence assertion was not
flagged. Skip that type argument, as sqlparser's conversion parse did;
function calls in the value argument still count.
* fix(rules): match unanchored set-operation branches to their SELECT tokens
A set-operation branch whose items carry no Polyglot span, such as
SELECT CAST(1 AS INTEGER), CAST('games' AS VARCHAR) after an aliased
first branch, found no SELECT token region. Its SQBRCONTRACT105 cast
types then fell back to Polyglot's spelling and its findings to 1:1,
producing false contract findings. Such a select now takes the next
unclaimed SELECT region after the previous branch, since branches and
CTEs are read in source order.1 parent 06de776 commit bfaff24
46 files changed
Lines changed: 3253 additions & 1669 deletions
File tree
- crates
- sqlbuild-analysis/src/semantic_validation
- _helpers
- main
- sqlbuild-rules
- src
- engine
- _helpers
- tests
- query_facts
- _helpers
- main
- rules
- _helpers
- main
- sqlbuild-sqltext
- src/sql_scan
- _helpers
- main
- tests/e2e/src/sqlbuild/cli/commands/main/rules
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
114 | 113 | | |
115 | 114 | | |
116 | 115 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
178 | 189 | | |
179 | 190 | | |
180 | 191 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
31 | 38 | | |
32 | 39 | | |
33 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
| 191 | + | |
191 | 192 | | |
192 | 193 | | |
193 | 194 | | |
| |||
203 | 204 | | |
204 | 205 | | |
205 | 206 | | |
| 207 | + | |
206 | 208 | | |
207 | 209 | | |
208 | 210 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| |||
0 commit comments