Skip to content

fix: Reject negative RANGE window frame offsets - #25816

Open
goutamadwant wants to merge 1 commit into
apache:mainfrom
goutamadwant:fix-negative-range-offsets-24902
Open

goutamadwant wants to merge 1 commit into
apache:mainfrom
goutamadwant:fix-negative-range-offsets-24902

Conversation

@goutamadwant

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Negative RANGE frame offsets can pass planning and cause an execution panic or incorrect window results. ROWS and GROUPS offsets are already rejected during planning.

What changes are included in this PR?

  • Reject negative numeric RANGE offsets and intervals with any negative component after type coercion, for both PRECEDING and FOLLOWING bounds.
  • Check the original wider value when coercion to a narrow ORDER BY type would otherwise turn a negative offset into an unbounded bound.
  • Add optimizer unit tests and SQL logic regressions for negative, mixed-sign, and narrow-overflow cases.

What is the testing strategy for this PR?

  • Both new optimizer unit tests pass.
  • The window SQL logic selection passes (7 files).
  • cargo fmt --all -- --check
  • cargo clippy --all-targets --all-features -- -D warnings

Are there any user-facing changes?

Negative RANGE offsets now produce a planning error instead of reaching execution. There is no public API change.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.88764% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.51%. Comparing base (acf5c89) to head (f754705).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
datafusion/optimizer/src/analyzer/type_coercion.rs 89.88% 2 Missing and 7 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #25816      +/-   ##
==========================================
+ Coverage   82.50%   82.51%   +0.01%     
==========================================
  Files        1141     1141              
  Lines      438825   439887    +1062     
  Branches   438825   439887    +1062     
==========================================
+ Hits       362050   362989     +939     
- Misses      54892    54947      +55     
- Partials    21883    21951      +68     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Negative INTERVAL offsets in RANGE window frames are accepted and panic at execution

2 participants