Repository navigation
Commit 4b3b621
fix(validate): fold uppercase metadata to the engine's identifier case; skip existence checks without a schema (AltimateAI#1343)
* fix(validate): fold uppercase metadata to the engine's identifier case; skip existence checks without a schema
`altimate_core_validate` rejected correct Snowflake SQL against real
metadata. The engine compares an unquoted identifier in lowercase and a
quoted one exactly; `schema_inspect` and `snowflake_get_table_stats`
return UPPERCASE names, so every query came back ColumnNotFound — with
the engine's own DidYouMean pointing at the same column in uppercase at
confidence 1 — and uppercasing the SQL did not help because the engine
lowercased it again. The model looped three or four validation rounds
per warehouse demo before giving up on the validator (AltimateAI#1333).
`normalizeSchemaContext` now folds an all-uppercase table or column
name — the storage form of an identifier created unquoted — to
lowercase before the schema reaches the engine. Mixed-case names were
created quoted, must be referenced quoted, and are matched exactly by
the engine, so they are left alone; lowercase names are already in the
engine's form. Applies to both schema_context shapes.
Without a schema the engine ran against the `_empty_` placeholder and
reported every table as missing, while the tool's description promised
existence checks are skipped. The handler now drops TableNotFound /
ColumnNotFound findings when no schema was given and recomputes `valid`
from what remains, so syntax and dialect errors still surface.
Tests: the exact query and uppercase metadata from the issue validate
(lower and upper SQL); a genuinely missing column is still reported; no
schema → valid for a correct query, still invalid for a syntax error;
fold and existence-classifier unit cases. Both guards were deleted once
to confirm the tests fail.
Closes AltimateAI#1333
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012Q51zFUmPg1WwtS5CrGJE6
* fix(validate): quoted uppercase references, fold collisions, table-less contexts
Bot review on AltimateAI#1343, checked against the engine: it lowercases table keys at
load, keeps column names as written, lowercases an unquoted reference and
matches a quoted one exactly, and dedups columns case-insensitively (first
wins) — so both spellings of a name cannot be emitted.
- `foldQuotedIdentifierCase`: a quoted all-uppercase identifier in the SQL
(`"ORDER_MONTH"`, dbt `quote_columns` / BI style on Snowflake) is lowercased
inside its quotes when a schema is present, so it matches the folded
metadata; same length, still quoted, string literals and comments stepped
over, mixed-case left exact
- A fold that would collide with an entry the schema already carries
(`ORDERS` + `orders`, `FOO` + `foo` columns) keeps the name as written
instead of overwriting; null-prototype maps so `__PROTO__` is an entry
- `schemaProvided`: a `schema_context` counts only if it normalises to a
table. `{ tables: {} }` / `{ users: {} }` used to fail the call outright
("Schema must define at least one table"); they now take the no-schema path
- Test: engine-dependent modules imported lazily behind a `require.resolve`
guard so the skip really skips; prior `ALTIMATE_TELEMETRY_DISABLED`
restored; dispatcher reset after the suite; cases for each of the above
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012Q51zFUmPg1WwtS5CrGJE6
* fix(validate): fold both halves for every SQL-plus-schema operation, schema files too
Codex review of AltimateAI#1343 (gpt-5.6-sol).
- Only `validate` folded the SQL; the other operations that match SQL
against a schema (lint, explain, check incl. lintDiff/base_sql, fix,
policy, semantics, testgen, equivalence, rewrite, correct, grade,
query_pii, column_lineage, track_lineage, complete, optimize_for_query,
prune_schema) got the folded schema with unfolded SQL — the mismatch the
fold exists to remove. `prepareSql` now hands every one of them the pair
- The fold is explicit (`normalizeSchemaContext(ctx, { fold })`): schema-only
operations (diff, export, fingerprint, classify, resolve_term) see the
names as written
- `schema_path` took the SQL half without the schema half: a JSON/YAML file
is now normalised and folded like an inline context; a DDL file is loaded
as-is and the SQL left alone
- Lexer: BigQuery/Databricks backticks fold too; a doubled quote inside a
name keeps it as written; dotted quoted names fold as one; `$tag$…$tag$`
and `E'…'` (backslash escapes) are opaque spans
- The tool decided `has_schema` on its own and reported "VALID" for a
table-less context as if existence had been checked; the handler says it
now. A failed schema load (`success: false`) is an engine failure, not a
valid result
- Tests for each; `isExistenceError` gets a code-only fixture
Not changed: the fold is dialect-blind. On a lowercase-folding warehouse an
uppercase metadata name can be a genuinely quoted identifier, and an
unquoted reference to it then validates; the tool has no dialect input to
scope by. Same class as the tradeoff already noted in `foldIdentifierCase`.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012Q51zFUmPg1WwtS5CrGJE6
* fix(validate): fold only names the schema holds, one preparation per schema source
Bot review of 8ecf029 on AltimateAI#1343.
- The SQL fold touched every quoted all-uppercase token, and on
MySQL/BigQuery/SQLite `"SHIPPED"` is a string literal: a query's values
changed under validation. Only tokens whose lowercase form is a name the
folded schema holds (table keys, each dotted segment, columns) are folded
- `hasSchema` was not a fold flag: for a DDL file the head SQL was left as
written but `base_sql` and lineage queries were folded, and the PII base
comparison used the raw base. `prepareSql` exposes `foldSql`, the same
preparation for any sibling SQL against that schema — identity for DDL —
and `check` (lintDiff + PII subtraction), `equivalence` and
`track_lineage` use it
- `sql.analyze`, `sql.optimize`, `sql.fix`, `sql.rewrite`, `sql.diff` and
`lineage.check` (`native/sql/register.ts`) match SQL against a schema too
and were still on the unfolded resolver; they prepare the pair now
- Test guard uses `require` (loads the binding) rather than `require.resolve`;
the temp schema directory is removed; a comment named the wrong handler
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012Q51zFUmPg1WwtS5CrGJE6
* fix(validate): give generated SQL back in the caller's spelling; diff from raw inputs
Bot review of 449513d on AltimateAI#1343 (third round).
- The fold leaked into engine output: `sql.rewrite`/`fix`/`optimize` and the
`altimate_core` rewrite/fix/correct/complete/optimize_for_query/testgen
handlers returned SQL with the validation-time lowercase spelling, which a
case-sensitive warehouse would not resolve. `prepareSql` records every token
it folded and exposes `unfold`, which restores the caller's spelling in any
string of the result (walking objects and arrays); those handlers use it
- `sql.diff` rendered its text diff from the folded copies, hiding a case-only
edit; it renders from the raw inputs and folds only for the equivalence check
- The dollar-quote branch requires an identifier boundary (`foo$t$` is an
identifier, not a string start)
- A JSON/YAML schema file that parses to zero tables takes the no-schema path
instead of failing in `Schema.fromJson`
- Tests: the sql.*/lineage case uses unquoted lowercase references and asserts
on the raw lineage source (an unfolded resolver fails it); generated-SQL
spelling across six handlers (disabling `unfold` fails it); the diff case;
the dollar boundary; the zero-table file
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012Q51zFUmPg1WwtS5CrGJE6
* test(validate): assert success before the spelling checks; do not endorse the quoted-lowercase equivalence
(bot review)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012Q51zFUmPg1WwtS5CrGJE6
* test(validate): sql.fix reports success=false with a fixed_sql when nothing needed fixing
Guard on "the handler ran and returned SQL" instead.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012Q51zFUmPg1WwtS5CrGJE6
---------
Co-authored-by: Claude Opus 5 <[email protected]>1 parent 13cab51 commit 4b3b621
5 files changed
Lines changed: 729 additions & 81 deletions
File tree
- packages/opencode
- src/altimate
- native
- sql
- tools
- test/altimate
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
22 | 31 | | |
23 | 32 | | |
24 | 33 | | |
| |||
89 | 98 | | |
90 | 99 | | |
91 | 100 | | |
92 | | - | |
93 | | - | |
| 101 | + | |
| 102 | + | |
94 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
95 | 117 | | |
96 | 118 | | |
97 | 119 | | |
| |||
101 | 123 | | |
102 | 124 | | |
103 | 125 | | |
104 | | - | |
105 | | - | |
| 126 | + | |
| 127 | + | |
106 | 128 | | |
107 | 129 | | |
108 | 130 | | |
| |||
156 | 178 | | |
157 | 179 | | |
158 | 180 | | |
159 | | - | |
160 | | - | |
| 181 | + | |
| 182 | + | |
161 | 183 | | |
162 | 184 | | |
163 | 185 | | |
| |||
168 | 190 | | |
169 | 191 | | |
170 | 192 | | |
171 | | - | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
172 | 197 | | |
173 | 198 | | |
174 | 199 | | |
175 | 200 | | |
176 | | - | |
| 201 | + | |
177 | 202 | | |
178 | 203 | | |
179 | 204 | | |
180 | 205 | | |
181 | | - | |
| 206 | + | |
182 | 207 | | |
183 | | - | |
184 | | - | |
| 208 | + | |
| 209 | + | |
185 | 210 | | |
186 | 211 | | |
187 | | - | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
188 | 215 | | |
189 | | - | |
| 216 | + | |
190 | 217 | | |
191 | 218 | | |
192 | 219 | | |
193 | 220 | | |
194 | 221 | | |
195 | 222 | | |
196 | | - | |
| 223 | + | |
197 | 224 | | |
198 | 225 | | |
199 | 226 | | |
| |||
238 | 265 | | |
239 | 266 | | |
240 | 267 | | |
241 | | - | |
242 | | - | |
| 268 | + | |
| 269 | + | |
243 | 270 | | |
244 | 271 | | |
245 | 272 | | |
246 | 273 | | |
247 | 274 | | |
248 | 275 | | |
249 | 276 | | |
250 | | - | |
| 277 | + | |
251 | 278 | | |
252 | 279 | | |
253 | 280 | | |
| |||
358 | 385 | | |
359 | 386 | | |
360 | 387 | | |
361 | | - | |
362 | | - | |
363 | | - | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
364 | 392 | | |
365 | 393 | | |
366 | 394 | | |
| |||
370 | 398 | | |
371 | 399 | | |
372 | 400 | | |
373 | | - | |
374 | | - | |
| 401 | + | |
| 402 | + | |
375 | 403 | | |
376 | 404 | | |
377 | 405 | | |
| |||
382 | 410 | | |
383 | 411 | | |
384 | 412 | | |
385 | | - | |
386 | | - | |
| 413 | + | |
| 414 | + | |
387 | 415 | | |
388 | 416 | | |
389 | 417 | | |
| |||
394 | 422 | | |
395 | 423 | | |
396 | 424 | | |
397 | | - | |
398 | | - | |
399 | | - | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
400 | 428 | | |
401 | 429 | | |
402 | 430 | | |
| |||
405 | 433 | | |
406 | 434 | | |
407 | 435 | | |
408 | | - | |
| 436 | + | |
409 | 437 | | |
410 | 438 | | |
411 | 439 | | |
412 | 440 | | |
413 | 441 | | |
414 | 442 | | |
415 | | - | |
| 443 | + | |
416 | 444 | | |
417 | 445 | | |
418 | 446 | | |
| |||
449 | 477 | | |
450 | 478 | | |
451 | 479 | | |
452 | | - | |
453 | | - | |
454 | | - | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
455 | 483 | | |
456 | 484 | | |
457 | 485 | | |
| |||
460 | 488 | | |
461 | 489 | | |
462 | 490 | | |
463 | | - | |
464 | | - | |
465 | | - | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
466 | 494 | | |
467 | 495 | | |
468 | 496 | | |
| |||
472 | 500 | | |
473 | 501 | | |
474 | 502 | | |
475 | | - | |
476 | | - | |
| 503 | + | |
| 504 | + | |
477 | 505 | | |
478 | 506 | | |
479 | 507 | | |
| |||
500 | 528 | | |
501 | 529 | | |
502 | 530 | | |
503 | | - | |
504 | | - | |
| 531 | + | |
| 532 | + | |
505 | 533 | | |
506 | 534 | | |
507 | 535 | | |
| |||
524 | 552 | | |
525 | 553 | | |
526 | 554 | | |
527 | | - | |
528 | | - | |
| 555 | + | |
| 556 | + | |
529 | 557 | | |
530 | 558 | | |
531 | 559 | | |
| |||
535 | 563 | | |
536 | 564 | | |
537 | 565 | | |
538 | | - | |
539 | | - | |
| 566 | + | |
| 567 | + | |
540 | 568 | | |
541 | 569 | | |
542 | 570 | | |
| |||
577 | 605 | | |
578 | 606 | | |
579 | 607 | | |
580 | | - | |
581 | | - | |
582 | | - | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
583 | 611 | | |
584 | 612 | | |
585 | 613 | | |
| |||
599 | 627 | | |
600 | 628 | | |
601 | 629 | | |
602 | | - | |
603 | | - | |
604 | | - | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
605 | 633 | | |
606 | 634 | | |
607 | 635 | | |
| |||
610 | 638 | | |
611 | 639 | | |
612 | 640 | | |
613 | | - | |
614 | | - | |
| 641 | + | |
| 642 | + | |
615 | 643 | | |
616 | 644 | | |
617 | 645 | | |
| |||
0 commit comments