Skip to content

fix: ignore ordering in approx_median - #27159

Draft
Phoenix500526 wants to merge 1 commit into
apache:mainfrom
Phoenix500526:issue/27157
Draft

Phoenix500526 wants to merge 1 commit into
apache:mainfrom
Phoenix500526:issue/27157

Conversation

@Phoenix500526

Copy link
Copy Markdown
Contributor

Important

Fork CI setup: For pull requests from a fork to main, enable workflows in your fork's Actions tab before you push.
See the fork CI setup guide.

Which issue does this PR close?

Rationale for this change

APPROX_MEDIAN(x ORDER BY k) incorrectly passes the sort key to the shared percentile accumulator, which treats it as a percentile argument. For an integer sort key, this causes:

What changes are included in this PR?

  • Declare APPROX_MEDIAN as order-insensitive so the framework discards unnecessary aggregate ORDER BY keys.
  • Add an SLT regression test for the reported query.

What is the testing strategy for this PR?

  • Confirmed the regression test fails with the cached pre-fix test executable and passes with the fix.
  • Passed aggregate.slt and the workspace extended test suite.
  • Passed cargo fmt --all and cargo clippy --all-targets --all-features -- -D warnings.

Are there any user-facing changes?

Queries such as the following now return 2.0 instead of an error:

SELECT approx_median(x ORDER BY k)
FROM (VALUES (1.0, 3), (2.0, 1), (3.0, 2)) t(x, k);

Sort keys must not be treated as percentile arguments by the
shared accumulator.

CLOSES apache#27157
@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Nov 6, 2026
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.

APPROX_MEDIAN with ORDER BY incorrectly treats the sort key as a percentile argument

1 participant