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

   ## Which issue does this PR close?
   
   Closes #24327.
   
   ## What changes are included in this PR?
   
   Allow RANGE window frames whose ORDER BY column is of type Binary, 
LargeBinary, BinaryView, or FixedSizeBinary. Free RANGE frames (only UNBOUNDED 
/ CURRENT ROW bounds) are now supported; finite-offset RANGE frames emit a 
planning error.
   
   ## Why are these changes needed?
   
   The default window frame for `OVER (ORDER BY x)` is `RANGE BETWEEN UNBOUNDED 
PRECEDING AND CURRENT ROW`. When `x` is a binary type, this incorrectly 
produces an internal error "Cannot run range queries on datatype: Binary" 
during type coercion, even though the frame has no finite offsets and only 
needs ordering comparisons (which Binary supports).
   
   ## What changes were made?
   
   1. **`extract_window_frame_target_type`**: Added `col_type.is_binary()` and 
`col_type.is_fixed_size_binary()` to the allowed type list, so binary ORDER BY 
columns are accepted for RANGE window frames.
   
   2. **`coerce_window_frame`**: Added a check that rejects finite-offset RANGE 
frames on binary types with a planning error, since binary types don't support 
the arithmetic needed for offset computation.
   
   3. **`has_finite_offset` helper**: A new function that checks whether a 
window frame bound is a finite offset (not UNBOUNDED or CURRENT ROW).
   
   ## Are there any user-facing changes?
   
   - Queries like `SELECT x, COUNT(*) OVER (ORDER BY x) FROM t` where `x` is 
Binary now succeed (was: internal error).
   - Queries like `RANGE BETWEEN 1 PRECEDING AND CURRENT ROW` on a binary 
column now produce a clear planning error instead of an internal error.
   - Explicit `ROWS` frame (e.g., `ORDER BY x ROWS BETWEEN UNBOUNDED PRECEDING 
AND CURRENT ROW`) already worked and continues to work.


-- 
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