Skip to content

fix(convert): refuse == and convert TOP and FETCH FIRST to LIMIT - #183

Merged
kvlonge merged 3 commits into
mainfrom
feat/convert-top-fetch-refuse-double-equals
Nov 12, 2026
Merged

kvlonge merged 3 commits into
mainfrom
feat/convert-top-fetch-refuse-double-equals

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Why

Three demo queries came out wrong. == converted to = although Snowflake rejects it, and TOP n and FETCH FIRST n ROWS ONLY were refused although LIMIT expresses them exactly.

Changes

  • == is now a check finding, SQ0206 double_equals, worded as Snowflake reports it: "Unknown function ==", with help to compare with =. Snowflake parses == and rejects it when compiling (errno 2139, recorded in corpora/everyday/snowflake-receipts.json), so parsing still accepts it, and the finding refuses the statement before conversion. The diagnostics reference is regenerated.
  • TOP n and FETCH { FIRST | NEXT } n { ROW | ROWS } [ ONLY ] convert to LIMIT n, after ORDER BY and DISTINCT. PERCENT, WITH TIES, a count that is not an integer literal, and more than one of LIMIT, TOP and FETCH stay refused.

Converted SQL in the playground corpora (basics, everyday, everyday-models, examples), before and after. Only these 3 of 2,962 statements change:

Query Before After
SELECT TOP 5 * FROM orders refused SQ0002 SELECT ... FROM "ORDERS" AS "ORDERS" LIMIT 5
SELECT order_id FROM orders FETCH FIRST 10 ROWS ONLY refused SQ0002 SELECT "ORDERS"."ORDER_ID" AS "ORDER_ID" FROM "ORDERS" AS "ORDERS" LIMIT 10
SELECT order_id FROM orders WHERE status == 'shipped' converted to = 'shipped' check SQ0206 Unknown function ==

Verification

  • Replay: the 8 recorded top-n and limit.fetch cases go from refused to matching, and their 8 obligations are met. 0 regressions. The translation results and SQL size baselines are re-recorded.
  • Corpus verdicts are unchanged, and no Snowflake syntax receipt has == as an operator.
  • New tests cover == rejections and non-rejections (strings, comments, >=, !=), check exiting 1 with SQ0206, TOP/FETCH rows run on DuckDB, and the PERCENT, WITH TIES and TOP-with-LIMIT refusals.
  • make check-ci passes.

@kvlonge
kvlonge force-pushed the fix/snowflake-clause-keyword-columns branch from a54615e to 3eea2bc Compare November 11, 2026 19:10
@kvlonge
kvlonge force-pushed the feat/convert-top-fetch-refuse-double-equals branch from 56c935b to a0dba58 Compare November 11, 2026 21:24
Base automatically changed from fix/snowflake-clause-keyword-columns to main November 11, 2026 23:30
Snowflake parses == and then rejects it when compiling, as a call to an
unknown function (errno 2139, recorded in the everyday corpus for
WHERE status == 'shipped'). SQLQuack read it as = and converted it. A
check finding now names it "Unknown function ==" with help to compare
with =, and refuses the statement before conversion. Parsing still
accepts it, as Snowflake does.
TOP n and FETCH { FIRST | NEXT } n { ROW | ROWS } [ ONLY ] keep the first n
rows exactly as LIMIT n does, after ORDER BY and DISTINCT. The recorded
top-n and limit.fetch cases now replay as matching. PERCENT, WITH TIES and
a query that combines LIMIT, TOP or FETCH stay refused, since LIMIT cannot
express them.
…ke rejects it

The analysis test still expected TOP to be refused as a missing rule.
TOP now converts as LIMIT, TOP PERCENT is refused, and == is refused
before conversion.
@kvlonge
kvlonge force-pushed the feat/convert-top-fetch-refuse-double-equals branch from a0dba58 to 1fd11a5 Compare November 11, 2026 23:33
@kvlonge
kvlonge added this pull request to the merge queue Nov 12, 2026
Merged via the queue into main with commit 6036370 Nov 12, 2026
13 checks passed
@kvlonge
kvlonge deleted the feat/convert-top-fetch-refuse-double-equals branch November 12, 2026 00:50
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