Skip to content

fix(snowflake/parser): optional FETCH noise words + TOP count must not consume infix *#297

Merged
h3n4l merged 1 commit into
mainfrom
fix/snowflake/fetch-top
Jun 10, 2026
Merged

fix(snowflake/parser): optional FETCH noise words + TOP count must not consume infix *#297
h3n4l merged 1 commit into
mainfrom
fix/snowflake/fetch-top

Conversation

@h3n4l

@h3n4l h3n4l commented Jun 10, 2026

Copy link
Copy Markdown
Member

Fix

Two Snowflake grammar regressions vs legacy ANTLR + official docs, found by the bytebase cutover differential (db/snowflake LIMIT-rewriter yaml):

  1. Strict FETCH: parseLimitOffsetFetch required FETCH {FIRST|NEXT} n {ROW|ROWS} ONLY in full; all noise words are optional per docs + legacy (FETCH 123, OFFSET 12 FETCH 123 now parse). FetchClause Loc.End = last consumed token.
  2. TOP eats *: TOP count used parseExpr, so SELECT TOP 125 * FROM t lexed 125 * as multiplication. New parseTopCount() accepts a single primary (number / $var / parenthesized) and never consumes infix operators.

Tests

8 new parser tests (bare/partial FETCH forms incl. Loc-span, TOP star + regression + negatives) + 3 deparse round-trips. Full go test ./snowflake/... -count=1 green incl. corpus. Orchestrator verified on a fresh checkout of 8170c3e9.

🤖 Generated with Claude Code

@h3n4l
h3n4l merged commit 213c505 into main Jun 10, 2026
2 checks passed
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