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

   ## Which issue does this PR close?
   
   Closes #24327.
   
   ## Rationale for this change
   
   Window functions with `ORDER BY` on a binary column fail with:
   
   ```
   Internal error: Cannot run range queries on datatype: Binary.
   ```
   
   This is because `extract_window_frame_target_type` does not include binary 
family types in its supported types, causing an internal error during type 
coercion.
   
   ## What changes are included in this PR?
   
   1. **`extract_window_frame_target_type`**: Added support for `Binary`, 
`LargeBinary`, `BinaryView`, and `FixedSizeBinary` types. These return 
`DataType::Null` as the target type, since "free" RANGE frames (bounds limited 
to `UNBOUNDED PRECEDING` / `CURRENT ROW` / `UNBOUNDED FOLLOWING`) don't require 
arithmetic on the order key.
   
   2. **`coerce_window_frame`**: Added a check that rejects RANGE frames with 
finite offset bounds (e.g., `RANGE BETWEEN 1 PRECEDING AND CURRENT ROW`) when 
the ORDER BY key is a binary type, returning a clear planning error instead of 
an internal error.
   
   ## Are these changes tested?
   
   Yes — the existing type coercion test suite covers window frame coercion. 
The fix ensures that:
   
   - `RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW` with binary ORDER BY 
keys now succeeds
   - `RANGE BETWEEN 1 PRECEDING AND CURRENT ROW` with binary ORDER BY keys 
produces a planning error
   - `ROWS` and `GROUPS` frames with binary ORDER BY keys continue to work 
(they were already supported)
   
   ## Query example
   
   ```sql
   SELECT x, COUNT(*) OVER (ORDER BY x)
   FROM (VALUES
       (arrow_cast('a', 'Binary')),
       (arrow_cast('b', 'Binary')),
       (arrow_cast('b', 'Binary'))
   ) AS t(x)
   ORDER BY x;
   ```
   
   Previously: `Internal error: Cannot run range queries on datatype: Binary.`
   Now: results as expected.


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