Repository navigation
fix(ddx-ad): write between as SQL's BETWEEN - #281
Merged
Merged
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 56 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
alxmrs
force-pushed
the
fix/to-sql-between
branch
2 times, most recently
from
November 19, 2026 16:47
bb0fb4d to
c58c550
Compare
This was referenced Nov 19, 2026
DuckDB's optimizer folds a range filter on an integer, `i1 >= 0 AND i1 < 2`, into `between(i1, 0, 1)`, and its Substrait producer writes that call. ddx copies a filter it doesn't differentiate into its steps, and to_sql had no name for `between`, so the program couldn't run: "writing the function `between` as SQL: ddx does not know its name in SQL". to_sql now writes it as `x BETWEEN lo AND hi`, which holds both bounds, as Substrait's and DuckDB's `between` do, and which both dialects read. Fixes #263. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CvszJhH8pn8H9G69wEPMU2
alxmrs
force-pushed
the
fix/to-sql-between
branch
from
November 21, 2026 14:03
c58c550 to
9f753fd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
∂ Claude (ddx):
Fixes #263.
Why
On DuckDB, ddx planned a gradient through a range filter but couldn't run it: "writing the function
betweenas SQL: ddx does not know its name in SQL". Through a join's equality, DuckDB's optimizer derives a range filter for one side from the other's: fromb.i1 >= 0 AND b.i1 < 2anda.i1 = b.i1, it addsbetween(a.i1, 0, 2)toa's filter, besidea's own comparisons. Its Substrait producer writes that call. ddx copies a filter it doesn't differentiate into its steps as it is, andto_sqlhad no SQL forbetween. torch-sql'ssplitwrites each part as such a filter.How
to_sqlreadsbetween(x, lo, hi)as a newExpr::Betweenand writes(x BETWEEN lo AND hi), which both dialects read. DuckDB's producer drops whether each bound is held (between(a.i1, 0, 2)above excludes 2), so SQL'sBETWEEN, which holds both, is the widest the call could mean. The comparisons DuckDB keeps beside it make the rows exact.Edge cases
betweenappears only as such a derived filter.BETWEENin SQL, and every range on one table, are planned asgte/lte/gt/ltcomparisons. If DuckDB wrote an exclusivebetweenalone, ddx would keep a row at its bound.betweenwith other than three arguments is refused as an invalid plan.BETWEENgives, which is what DuckDB folded it from.Tests
test_duckdb.pyruns On DuckDB, a range filter can become a between call that ddx's SQL writer can't write #263's loss (two slices of one table, multiplied) and checks all 12 gradient entries. It fails on the released 0.4.10 with On DuckDB, a range filter can become a between call that ddx's SQL writer can't write #263's error.🤖 Generated with Claude Code
https://claude.ai/code/session_01CvszJhH8pn8H9G69wEPMU2