Commit 03787df
fix(ol_dbt_cli): sql_parser — fix 3 Jinja-collapse defects (trailing-comma CTE, alias loss, subquery FP) (#2454)
* fix(ol_dbt_cli): sql_parser — fix 3 Jinja-collapse defects (trailing-comma CTE, alias loss, subquery FP)
Closes the three remaining post-render collapse defects from the 2026-07-13
sql_parser audit (tk-...770aaa). After this, all 659 models parse (was 3
failing) and a full `ol-dbt validate` reports 0 ERRORs (was 1).
(1) TRAILING-COMMA CTE MACRO — a CTE-injecting macro followed by a comma
(`{{ deduplicate_raw_table(...) }},`) renders to `__macro__,` alone on its
line in a WITH list. The bare standalone-line rule only matched a placeholder
alone on its line, so the trailing comma left an invalid bare identifier and
sqlglot failed with "Could not find outermost SELECT" (3 stg__ models). Add a
rule that replaces it with a valid placeholder CTE — with a leading comma,
since these injector macros emit leading-comma CTEs and always follow a base
CTE that carries no trailing comma.
(2) NESTED-ALIAS LOSS — a multi-line `if(cond, a, {{ macro(...) }}) as alias`
(int__micromasters__program_certificates) was mis-collapsed: the broken-column
repair treated the `if`'s last argument as a split column and deleted the `)`,
swallowing the alias into the function and dropping the output column. Gate the
collapse on a parse check — it only runs when the SQL is *actually* broken
(unbalanced), which a well-formed multi-line function call is not.
(3) SUBQUERY FALSE POSITIVE — get_columns_read_from_ref Pass 2 descended into
nested subqueries via `clause.find_all(exp.Column)`, so
`where x in (select y from other_ref where other_col = ...)` attributed
`other_col` to the OUTER ref (the sole ERROR-level FP in a full validate run,
in edxorg_to_mitxonline_enrollments). Skip columns whose nearest enclosing
Select is not the passthrough source's own Select.
355 CLI tests pass (6 new), pre-commit (ruff+mypy) clean. Full-repo sweep: 0
parse errors across 659 models; full validate: 0 ERRORs.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* perf(ol_dbt_cli): gate the broken-column parse-check behind a cheap regex precheck
Addresses Copilot review on #2454: _collapse_broken_column_expressions called
_parses_cleanly (a full sqlglot parse) for every model, doubling parse work
across validate/impact. Add a _BROKEN_COL_RE.search() fast path so the parse
gate only runs when the broken-column shape is actually present. Measured over
the repo: the expensive parse now runs 15× across 659 models instead of 659×,
with 0 parse errors unchanged.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>1 parent e3b4c71 commit 03787df
3 files changed
Lines changed: 159 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
151 | 166 | | |
152 | 167 | | |
153 | 168 | | |
| |||
263 | 278 | | |
264 | 279 | | |
265 | 280 | | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
266 | 289 | | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
267 | 300 | | |
268 | 301 | | |
269 | 302 | | |
| |||
276 | 309 | | |
277 | 310 | | |
278 | 311 | | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
279 | 321 | | |
280 | 322 | | |
281 | 323 | | |
| |||
582 | 624 | | |
583 | 625 | | |
584 | 626 | | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
585 | 642 | | |
586 | 643 | | |
587 | 644 | | |
| |||
1001 | 1058 | | |
1002 | 1059 | | |
1003 | 1060 | | |
1004 | | - | |
1005 | | - | |
1006 | | - | |
1007 | | - | |
1008 | | - | |
1009 | | - | |
1010 | | - | |
1011 | | - | |
1012 | | - | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
1013 | 1077 | | |
1014 | 1078 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
261 | 298 | | |
262 | 299 | | |
263 | 300 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
307 | 356 | | |
308 | 357 | | |
309 | 358 | | |
| |||
0 commit comments