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.
To Reproduce
Run this self-contained query in datafusion-cli on current main:
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:
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:
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:
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;
Describe the bug
Window functions with an
ORDER BYexpression whose type isBinaryfail during type coercion when the window uses the default frame.To Reproduce
Run this self-contained query in
datafusion-clion currentmain:It fails with:
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:
Free RANGE frames whose bounds are only
UNBOUNDEDorCURRENT ROWshould support binary order keys. RANGE frames with finite offsets, such asRANGE 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: