Skip to content

fix: close correctness gaps in Rules, SQL scanners and sqb query - #848

Merged
kvlonge merged 8 commits into
mainfrom
fix/correctness-batch
Sep 27, 2026
Merged

kvlonge merged 8 commits into
mainfrom
fix/correctness-batch

Conversation

@kvlonge

@kvlonge kvlonge commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Why

Five small correctness gaps found while using SQLBuild on larger projects: two Rules missed common SQL forms, the compiler failed on valid dollar-quoted literals, sqb query printed Python tracebacks, and --no-sql-analysis buried real diagnostics under thousands of type-proof findings.

Changes

  • SQBRSQL023 reports unused table aliases written without AS. Join modifiers (POSITIONAL, ASOF, ...), clause keywords and whole-row alias uses (row_to_json(o), SELECT o) are never treated as unused, so the fix cannot break a query.
  • SQBRDECLARATION102 reports non-canonical numeric [NOT] BETWEEN bounds and [NOT] IN lists, suggesting a list or set constant for value lists.
  • Compiler reference scanners (Python and native) treat $$...$$ and $tag$...$tag$ as opaque literals, so apostrophes, -- and __ref( text inside them no longer break compilation or create dependencies.
  • sqb query reports warehouse errors as error[C108] with exit code 2 and no partial stdout.
  • With SQL analysis disabled, type-proof rules (SQBRCONTRACT105) are skipped with one stderr note instead of failing every typed column.

Verification

  • make check-ci and make test (7,820 passed) locally.
  • New Rust, unit, integration and DuckDB E2E tests for each change; regression cases fail on the previous code.
  • One independent review; its two SQBRSQL023 findings are fixed and verified.

SQBRSQL023 only recognised aliases introduced by AS, so an unused implicit alias such as `FROM orders o` went unreported. Implicit aliases after relation names, subqueries and table functions now follow the same unused-alias contract.

Refs CHI-376
SQBRDECLARATION102 only inspected binary comparison operators, so literal BETWEEN bounds and numeric IN/NOT IN members bypassed the rule. Range and value-list predicates are now evaluated like the equivalent comparisons, and value lists point to a list or set constant used through IN @const(...).

Refs CHI-397
The compiler's reference, macro, declaration, interpolation and resolution scanners only recognised quote characters, so an apostrophe inside a $$...$$ literal opened a phantom quote and compilation failed with an unclosed quoted string, while reference-shaped text inside dollar quotes could be extracted as a dependency. The Python scanners and the native compiler scan policy now skip $$ and $tag$ literals like single-quoted strings.

Refs CHI-375
A warehouse error from sqb query escaped the CLI error projection and printed a Python traceback. Query execution failures now raise a coded CLI error, error[C108], carrying the warehouse message on stderr with exit code 2 and no stdout output.

Refs CHI-343
SQBRCONTRACT105 needs inferred type proofs, which only exist when SQL analysis runs, so compile --no-sql-analysis (or sql_analysis = false) reported it for essentially every typed contract column. Type-proof rules are now not evaluated when the run or project disables SQL analysis, and compile prints one note naming the skipped rules on stderr before the final summary. With analysis enabled, behaviour is unchanged.

Refs CHI-353
… findings

SQBRSQL023 treated an unaliased relation's join or relation modifier, such as POSITIONAL in `FROM orders POSITIONAL JOIN customers`, as an implicit alias and offered to delete it. It also counted an alias as used only when followed by a dot, so whole-row uses such as `to_json(o)`, `SELECT o` or `WHERE o IS NOT NULL` were reported and their deletion broke binding. Modifier and clause keywords are no longer implicit-alias candidates, and any bare identifier reference to the alias counts as a use for both implicit and AS aliases.

Refs CHI-376
@kvlonge
kvlonge enabled auto-merge (squash) September 27, 2026 02:55
@kvlonge
kvlonge merged commit 0fe3fa5 into main Sep 27, 2026
30 checks passed
@kvlonge
kvlonge deleted the fix/correctness-batch branch September 27, 2026 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant