You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Window functions fail when ORDER BY uses a binary column #24327
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:
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:
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;
Activity
fix: Support RANGE window frames over binary ORDER BY keys
fix: Support RANGE window frames over binary ORDER BY keys
fix: Support RANGE window frames over binary ORDER BY keys
fix: Support RANGE window frames over binary ORDER BY keys
fix: Support RANGE window frames over binary ORDER BY keys
fix: Support RANGE window frames over binary ORDER BY keys
fix: Support RANGE window frames over binary ORDER BY keys (apache#24357