Skip to content

fix: median retract logic for sliding window frames#21300

Open
lyne7-sc wants to merge 1 commit intoapache:mainfrom
lyne7-sc:fix/median
Open

fix: median retract logic for sliding window frames#21300
lyne7-sc wants to merge 1 commit intoapache:mainfrom
lyne7-sc:fix/median

Conversation

@lyne7-sc
Copy link
Copy Markdown
Contributor

@lyne7-sc lyne7-sc commented Apr 1, 2026

Which issue does this PR close?

Rationale for this change

median could produce incorrect results for sliding window frames because MedianAccumulator::retract_batch could skip values after swap_remove(i).

When an element was removed, the last element was moved into index i, but the loop still incremented i. That meant the swapped-in value was never checked, so not all requested values were retracted.

What changes are included in this PR?

  • fix retract_batch so the index is only advanced when no value is removed
  • add a slt case for median over a sliding range window

Are these changes tested?

Yes.

Are there any user-facing changes?

No.

@github-actions github-actions bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Apr 1, 2026
break;
}
}
} else {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be simple, just re-check index i after swap_remove(i).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

median window function can skip retracted values in sliding frames

1 participant