fix(duckdb): Correct RANGE to Spark SEQUENCE transpilation for single-element ranges#7294
Merged
georgesittas merged 1 commit intotobymao:mainfrom Mar 16, 2026
Merged
Conversation
geooo109
approved these changes
Mar 16, 2026
georgesittas
approved these changes
Mar 16, 2026
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.
Fixes #7291
Summary
Fixes incorrect transpilation of DuckDB's
RANGE(start, stop)to Spark'sSEQUENCEwhen the range contains exactly one element.Problem
When transpiling
RANGE(1, 2)from DuckDB to Spark, the output was an empty array[]instead of[1].Example:
Root Cause
The condition for determining when to return an empty array used >= instead of >:
Before: IF((stop - 1) >= start, ARRAY(), SEQUENCE(...))
After: IF((stop - 1) > start, ARRAY(), SEQUENCE(...))
When stop = 2 and start = 1:
Before: (2 - 1) >= 1 → 1 >= 1 → TRUE → returns ARRAY() ❌
After: (2 - 1) > 1 → 1 > 1 → FALSE → returns SEQUENCE(1, 1) ✅
Changes
sqlglot/dialects/dialect.py(lines 2280, 2284):Changed
exp.GTEtoexp.GTfor positive step conditionChanged
exp.LTEtoexp.LTfor negative step conditiontests/dialects/test_duckdb.py:Updated existing test with correct expected output
Added 2 new test cases for edge case validation
Testing
✅ All existing DuckDB tests pass (349 subtests)
✅ All Spark tests pass
✅ New edge case tests added and passing
✅ Verified with multiple range values (1-1, 1-2, 1-3, 1-5, 0-10)