Skip to content

feat(sql): support APPROX_PERCENTILE WITHIN GROUP - #27864

Merged
mergify[bot] merged 1 commit into
matrixorigin:mainfrom
daviszhen:codex/issue-25110-approx-within-group
Aug 30, 2026
Merged

mergify[bot] merged 1 commit into
matrixorigin:mainfrom
daviszhen:codex/issue-25110-approx-within-group

Conversation

@daviszhen

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Related to #25110

What this PR does / why we need it:

This PR implements the next ordered-set aggregate step proposed in #25110.

  • Adds APPROX_PERCENTILE(p) WITHIN GROUP (ORDER BY value [ASC|DESC]).
  • Commonizes ordered-set aggregate binder validation and lowering for MEDIAN, approximate percentile, and exact percentile functions.
  • Keeps the existing APPROX_PERCENTILE(value, p) syntax and its window behavior unchanged.
  • Implements DESC semantics by converting p to the exact decimal complement 1-p before invoking the existing executor, without changing its aggregate configuration format.
  • Adds parser, planner, EXPLAIN, compiler, and BVT coverage plus a design note.

Testing

Passed locally:

  • go test -mod=readonly ./pkg/sql/parsers/dialect/mysql ./pkg/sql/plan ./pkg/sql/plan/explain ./pkg/sql/compile -count=1
  • go test -mod=readonly ./pkg/sql/colexec/aggexec -run ApproxPercentile -count=1
  • go test -mod=readonly -race ./pkg/sql/plan -run TestBuildOrderedSetAggregates|TestBuildApproxPercentileWithinGroup -count=1
  • go vet -mod=readonly ./pkg/sql/parsers/dialect/mysql ./pkg/sql/plan ./pkg/sql/plan/explain ./pkg/sql/compile
  • deterministic parser regeneration and git diff --check

BVT cases and expected results were added; a distributed BVT service was not run locally.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Deep review on exact head 2c465e45078bfff8336cf6747571d7e508ea1b21.

Design gate: PASS for this revision. The public SQL contract is coherent: the legacy two-argument/window form remains unchanged; the ordered-set form has one percentile argument and one ordered expression; DESC is lowered to an exact 1-p complement before the unchanged executor. No aggregate-state or wire-format change is introduced.

Implementation review: parser/binder/explain/compile ownership is consistent, percentile validation preserves NULL/constant/type/range rules, and exact decimal complementation avoids floating-point drift at boundaries. Invalid arity, multiple ORDER BY items, dynamic/NULL percentile, and WITHIN GROUP plus OVER are covered. The extra work is compile-time only and bounded by the percentile literal length; the aggregation hot path is unchanged.

Validation: exact-head UT/SCA/coverage and both selected BVT jobs are green; func_aggr_ordered_set.test is included in the successful pessimistic BVT assignment. I found no correctness, compatibility, performance, resource-lifecycle, or unhappy-path blocker.

@mergify mergify Bot added the queued label Aug 30, 2026
@mergify

mergify Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-30 06:52 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-08-30 06:52 UTC · at 2c465e45078bfff8336cf6747571d7e508ea1b21 · squash

This pull request spent 10 seconds in the queue, including 1 second running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)

@mergify
mergify Bot merged commit d57753d into matrixorigin:main Aug 30, 2026
27 of 28 checks passed
@mergify mergify Bot removed the queued label Aug 30, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
This PR implements the next ordered-set aggregate step proposed in matrixorigin#25110.

- Adds `APPROX_PERCENTILE(p) WITHIN GROUP (ORDER BY value [ASC|DESC])`.
- Commonizes ordered-set aggregate binder validation and lowering for `MEDIAN`, approximate percentile, and exact percentile functions.
- Keeps the existing `APPROX_PERCENTILE(value, p)` syntax and its window behavior unchanged.
- Implements DESC semantics by converting `p` to the exact decimal complement `1-p` before invoking the existing executor, without changing its aggregate configuration format.
- Adds parser, planner, EXPLAIN, compiler, and BVT coverage plus a design note.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
This PR implements the next ordered-set aggregate step proposed in matrixorigin#25110.

- Adds `APPROX_PERCENTILE(p) WITHIN GROUP (ORDER BY value [ASC|DESC])`.
- Commonizes ordered-set aggregate binder validation and lowering for `MEDIAN`, approximate percentile, and exact percentile functions.
- Keeps the existing `APPROX_PERCENTILE(value, p)` syntax and its window behavior unchanged.
- Implements DESC semantics by converting `p` to the exact decimal complement `1-p` before invoking the existing executor, without changing its aggregate configuration format.
- Adds parser, planner, EXPLAIN, compiler, and BVT coverage plus a design note.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
This PR implements the next ordered-set aggregate step proposed in matrixorigin#25110.

- Adds `APPROX_PERCENTILE(p) WITHIN GROUP (ORDER BY value [ASC|DESC])`.
- Commonizes ordered-set aggregate binder validation and lowering for `MEDIAN`, approximate percentile, and exact percentile functions.
- Keeps the existing `APPROX_PERCENTILE(value, p)` syntax and its window behavior unchanged.
- Implements DESC semantics by converting `p` to the exact decimal complement `1-p` before invoking the existing executor, without changing its aggregate configuration format.
- Adds parser, planner, EXPLAIN, compiler, and BVT coverage plus a design note.

Approved by: @XuPeng-SH

This branch was previously deployed

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

Labels

kind/enhancement size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants