Skip to content

fix: support RANGE window frames with binary ORDER BY (#24327) - #24344

Open
waterWang wants to merge 1 commit into
apache:mainfrom
waterWang:fix/window-binary-range-order-by-24327
Open

fix: support RANGE window frames with binary ORDER BY (#24327)#24344
waterWang wants to merge 1 commit into
apache:mainfrom
waterWang:fix/window-binary-range-order-by-24327

Conversation

@waterWang

Copy link
Copy Markdown

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.

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 rather than an internal error.

The default window frame for `OVER (ORDER BY x)` is
`RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW`, which is a free
frame and should work for any type that supports ordering.

Closes apache#24327
@github-actions github-actions Bot added the optimizer Optimizer rules label Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimizer Optimizer rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Window functions fail when ORDER BY uses a binary column

1 participant