fornwall opened a new pull request, #24357: URL: https://github.com/apache/datafusion/pull/24357
Closes https://github.com/apache/datafusion/issues/24327. A window with an `ORDER BY` over a binary column and no explicit frame gets the default `RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW`. Computing that frame's bounds goes through `extract_window_frame_target_type`, which had no arm for the binary types, so any window function whose leading `ORDER BY` key was `Binary`/`LargeBinary`/`BinaryView`/`FixedSizeBinary` failed with: Internal error: Cannot run range queries on datatype: Binary Binary is orderable, so peer/range comparison is well defined for it in exactly the same way it already is for `Utf8`. Accept the binary types alongside the string types. A finite RANGE offset such as `1 PRECEDING` asks for more than ordering: the bound is computed as `current_value - 1`, so the order key type must also support arithmetic. Binary does not, and neither do the `Utf8`, `Boolean`, `List` and `Null` order keys that `extract_window_frame_target_type` already accepted. For those, `ScalarValue::sub_checked` failed during execution and the error was swallowed by the overflow handling from #22140, which collapses a failed bound to the partition edge. So SELECT COUNT(*) OVER (ORDER BY x RANGE BETWEEN 1 PRECEDING AND CURRENT ROW) FROM (VALUES ('a'), ('b'), ('c')) t(x) silently returned the running count 1, 2, 3 -- the whole partition -- rather than an error. Reject the offset form during planning for every target type that has no arithmetic. For the string, boolean, list and null order keys this turns a wrong result into a plan error, which matches PostgreSQL's "RANGE with offset PRECEDING/FOLLOWING is not supported for column type ...". `WindowFrame::free_range()` becomes public so that check can be expressed in the vocabulary the crate already uses for "bounds that need no arithmetic". Document the restriction in the window functions user guide, and the changed SQL behavior in the 55.0.0 upgrade guide. ## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes #. ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. Please explain the problem you are trying to solve in terms of the user-visible behavior, rather than the implementation. For example, "The code in `foo.rs` doesn't handle nulls" is a symptom of the implementation. "COUNT(DISTINCT) returns wrong results when the column contains nulls" is the user-visible problem. --> ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here, but it is sometimes worth providing a summary of the individual changes in this PR. --> ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. If there are any breaking changes to public APIs, please add the `api change` label. --> -- 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]
