Repository navigation
Parse DuckDB's // integer division operator - #482
eddietejeda wants to merge 5 commits into
Conversation
|
Verdict: request changes before merging revision This addresses a real DuckDB parsing gap. Validation passed for all four new tests, 1,301 library tests, 208 dialect-matrix tests, and formatting. Additional execution probes identified the following concerns.
|
- Enable the existing double_slash_int_div tokenizer flag for DuckDB (already used by Vertica) instead of a bespoke parser lookahead; the existing DIV-keyword parsing path then handles it for free. Fixes separated/commented slashes (e.g. "7 / / 2") being wrongly accepted - Report unsupported instead of silently wrong output when a DuckDB // operand is a float literal, since DuckDB falls back to ordinary float division there (7.0 // 2 is 3.5, not 3) and truncating DIV forms can't reproduce that - Report unsupported for BigQuery when dividing by a literal zero, since BigQuery's DIV raises an error where DuckDB's // returns NULL - Emulate integer division for SQLite (CAST(CAST(x AS REAL) / y AS INTEGER)), which has no DIV function and previously got invalid SQL - Wire duckdb_integer_division into make test-rust-verify; expand coverage from 4 to 9 cases
- Move the float-operand guard into the DuckDB-source transform so it only applies to DuckDB's //; it had been placed in target-side code that can't see the source and broke MySQL's own DIV (7.5 DIV 2) and Vertica's //, which genuinely truncate - Reject a literal-zero divisor for every non-DuckDB target, not just BigQuery: PostgreSQL's DIV and ClickHouse's intDiv raise too, where DuckDB returns NULL - Recognize negated, parenthesized, and exponent-form float literals - Treat Vertica and ClickHouse as truncating targets for the float guard
DuckDB's // is ordinary float division when either operand is a float literal, so emit / (which then follows each target's own division rules) instead of reporting it unsupported. hotquery's hotdata target already lowered IntDiv to / and was producing the right answer here; the guard would have turned that into an error.
|
Addressed the three issues:
|
|
Thanks, I implemented some additional fixes and tests in #484. Closing. |
DuckDB has an integer division operator written as
//. Right now, the parser doesn't recognize it. See DuckDB operator list here: https://duckdb.org/docs/lts/sql/functions/numericWhat this does
When the source dialect is DuckDB and a
/is followed by another/, the parser now treats the pair as one operator and builds anIntDivnode.Nothing else is affected.
a / / bisn't valid SQL in any dialect, so there's no existing input this could change the meaning of. The check is also limited to DuckDB as the source.Tests
tests/duckdb_integer_division.rscovers the round trip, the lowering to other targets, precedence against+, and that a plain/still parses as ordinary division.