edubraqd opened a new pull request, #24903:
URL: https://github.com/apache/datafusion/pull/24903

   ## Which issue does this PR close?
   
   - Closes #24902.
   
   ## Rationale for this change
   
   ROWS and GROUPS frame offsets are parsed as `UInt64`, so a negative offset 
is a planning error. RANGE offsets are only typed once the ORDER BY type is 
known, and an interval literal such as `INTERVAL '-1 day'` carries its sign 
inside the string, so it was accepted. The resulting frame starts after it 
ends, which the execution code does not expect: it panics with "attempt to 
subtract with overflow" in debug builds (`sliding_aggregate.rs`, 
`window_state.rs`) and returns wrong results in release builds.
   
   ## What changes are included in this PR?
   
   After the RANGE offsets have been coerced in `coerce_window_frame`, compare 
each finite offset with the zero of its type and reject negative ones with a 
planning error, matching what ROWS / GROUPS already do at parse time (and what 
PostgreSQL does).
   
   ## Are these changes tested?
   
   Yes. `window.slt` gains three negative-offset cases (`PRECEDING`, 
`FOLLOWING`, both) that now fail at planning, plus a non-negative interval 
offset that still runs.
   
   ## Are there any user-facing changes?
   
   Queries with a negative interval offset in a RANGE frame now fail at 
planning instead of panicking or returning wrong results.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to