Skip to content

fix(lint): read a FIRST or LAST join alias as the relation alias - #212

Merged
kvlonge merged 1 commit into
mainfrom
fix/lint-first-last-alias
Nov 13, 2026
Merged

kvlonge merged 1 commit into
mainfrom
fix/lint-first-last-alias

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Why

Since 0.11.0 the Snowflake parser reads a bare FIRST or LAST after a joined table as that relation's alias. The lint's token path still took only identifier tokens as aliases and qualifiers. For JOIN t first ON …, LEFT JOIN t last USING (…) and CROSS JOIN t first, it therefore took the table name as the alias and reported SQLCLEAN032 ("Joined relation contributes no referenced values") although first.x is selected. CROSS JOIN also reported SQLCLEAN022 for first.x. The same statements with ordinary aliases reported neither.

Changes

  • A relation's alias or qualifier may be an identifier or FIRST or LAST. The unused-join check and the simple-projection check now both use this rule.
  • New lint cases, in their own test file: one per spelling (JOIN … ON, LEFT JOIN … USING, CROSS JOIN for SQLCLEAN032; CROSS JOIN and first.* EXCLUDE (…) for SQLCLEAN022), a control with an ordinary alias, and a LAST alias that is really unused, which still reports SQLCLEAN032 on the JOIN.

Verification

  • The new cases fail without the fix, and the EXCLUDE case fails when only the wildcard check is left unfixed.
  • With every SQLCLEAN rule enabled, the FIRST and LAST spellings now get the same findings as the same statements with aliases f and l.
  • cargo test -p sqlquack-lint passes.
  • make check-ci passed.

Snowflake reads a bare FIRST or LAST after a joined table as its alias,
which the parser accepts since 0.11.0. The lint's token path only took
identifier tokens as aliases and qualifiers, so for JOIN t first ON ...,
LEFT JOIN t last USING (...) and CROSS JOIN t first it took the table
name as the alias and reported SQLCLEAN032 although first.x is selected,
and it reported SQLCLEAN022 for first.x as an unnamed calculation.
@kvlonge
kvlonge enabled auto-merge November 12, 2026 23:34
@kvlonge
kvlonge added this pull request to the merge queue Nov 13, 2026
Merged via the queue into main with commit f009b82 Nov 13, 2026
13 checks passed
@kvlonge
kvlonge deleted the fix/lint-first-last-alias branch November 13, 2026 00:31
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