Skip to content

branch-4.0: [fix](fe) Preserve nth_value semantics for reversed window frames #64864#65020

Closed
morrySnow wants to merge 1 commit into
apache:branch-4.0from
morrySnow:pick-4.0-64864
Closed

branch-4.0: [fix](fe) Preserve nth_value semantics for reversed window frames #64864#65020
morrySnow wants to merge 1 commit into
apache:branch-4.0from
morrySnow:pick-4.0-64864

Conversation

@morrySnow

Copy link
Copy Markdown
Contributor

Cherry-pick of #64864 to branch-4.0.

#64864 - Preserve nth_value semantics for reversed window frames

Preserve nth_value semantics for reversed window frames by properly negating the offset argument and handling the reversed frame evaluation.

🤖 Generated with Claude Code

### What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary: Nereids reverses order keys and window frames for frames ending with UNBOUNDED FOLLOWING so BE can execute an equivalent supported frame shape. nth_value depends on the position within the frame, so reversing the order without adjusting its offset changes the result. This change lets BE interpret negative nth_value offsets as counting from the end of the frame, and rewrites nth_value's offset to 0 - offset when Nereids applies the reverse-window transformation.

### Release note

None

### Check List (For Author)

- Test: Manual test
    - Ran git diff --check for the modified BE and FE files. Did not compile per user request.
- Behavior changed: Yes. nth_value keeps equivalent semantics when the window frame is reversed for execution.
- Does this need documentation: No
@morrySnow morrySnow requested a review from morningman as a code owner June 30, 2026 07:44
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@morrySnow morrySnow closed this Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants