fix: support RANGE window frames with binary ORDER BY (#24327) - #24344
Open
waterWang wants to merge 1 commit into
Open
fix: support RANGE window frames with binary ORDER BY (#24327)#24344waterWang wants to merge 1 commit into
waterWang wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)isRANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW. Whenxis 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?
extract_window_frame_target_type: Addedcol_type.is_binary()andcol_type.is_fixed_size_binary()to the allowed type list, so binary ORDER BY columns are accepted for RANGE window frames.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.has_finite_offsethelper: 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?
SELECT x, COUNT(*) OVER (ORDER BY x) FROM twherexis Binary now succeed (was: internal error).RANGE BETWEEN 1 PRECEDING AND CURRENT ROWon a binary column now produce a clear planning error instead of an internal error.ROWSframe (e.g.,ORDER BY x ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) already worked and continues to work.