fornwall opened a new issue, #24327:
URL: https://github.com/apache/datafusion/issues/24327
### Describe the bug
Window functions with an `ORDER BY` expression whose type is `Binary` fail
during type coercion when the window uses the default frame.
An ordered window without an explicit frame uses:
```sql
RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
```
Binary values are orderable, so this frame can be evaluated by comparing
values and peers without performing arithmetic. However, planning currently
rejects the binary order key with an internal error.
### To Reproduce
Run this self-contained query in `datafusion-cli` on current `main`:
```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;
```
It fails with:
```text
Error: type_coercion
caused by
Internal error: Cannot run range queries on datatype: Binary.
```
The same problem affects `LargeBinary`, `BinaryView`, `FixedSizeBinary`, and
dictionary-wrapped binary values.
### Expected behavior
The query should succeed and treat equal binary values as peers. Its result
should be equivalent to:
```text
61 1
62 3
62 3
```
Free RANGE frames whose bounds are only `UNBOUNDED` or `CURRENT ROW` should
support binary order keys. RANGE frames with finite offsets, such as `RANGE
BETWEEN 1 PRECEDING AND CURRENT ROW`, should remain unsupported because they
require arithmetic on the order key, but should produce a planning error rather
than an internal error.
### Additional context
Using an explicit row-based frame avoids the error:
```sql
SELECT x, COUNT(*) OVER (
ORDER BY x ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
)
FROM (VALUES
(arrow_cast('a', 'Binary')),
(arrow_cast('b', 'Binary')),
(arrow_cast('b', 'Binary'))
) AS t(x)
ORDER BY x;
--
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]