Skip to content

feat: implement CUME_DIST window function - #23762

Merged
mergify[bot] merged 6 commits into
matrixorigin:mainfrom
ck89119:feat/win_cume_dist
Feb 26, 2026
Merged

mergify[bot] merged 6 commits into
matrixorigin:mainfrom
ck89119:feat/win_cume_dist

Conversation

@ck89119

@ck89119 ck89119 commented Feb 25, 2026 •

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:

issue #23011

What this PR does / why we need it:

Implement MySQL-compatible CUME_DIST() window function.

CUME_DIST() returns the cumulative distribution of a value within a partition.

Formula: (rows with values <= current row) / (total rows in partition)
Return type: DOUBLE, range (0, 1]

Changes

Parser

  • Add CUME_DIST keyword and syntax rule
  • Token constant: CUME_DIST = 57955

Executor

  • Implement cumeDistWindowExec structure with float64 return type
  • Implement flushCumeDist() algorithm
  • Register WinIdOfCumeDist = -30

Function Registration

  • Register CUME_DIST as WIN_ORDER function
  • Add to functionIdRegister map

Tests

  • Add SQL test cases covering ORDER BY, PARTITION BY, no ORDER BY, and duplicate values

Example Usage

SELECT a, b, CUME_DIST() OVER (ORDER BY a) FROM t1;
SELECT a, b, CUME_DIST() OVER (PARTITION BY a ORDER BY b) FROM t1;

Reference

https://dev.mysql.com/doc/refman/8.4/en/window-function-descriptions.html#function_cume-dist

Implement MySQL-compatible CUME_DIST() window function that returns
the cumulative distribution of a value within a partition.

Formula: (rows with values <= current row) / (total rows in partition)
Return type: DOUBLE, range (0, 1]

Changes:
- Parser: Add CUME_DIST keyword and syntax rule
- Executor: Implement cumeDistWindowExec with float64 return type
- Function: Register CUME_DIST as WIN_ORDER function
- Tests: Add SQL test cases

Reference: https://dev.mysql.com/doc/refman/8.4/en/window-function-descriptions.html#function_cume-dist
@mergify mergify Bot added the queued label Feb 26, 2026
@mergify
mergify Bot merged commit 416d612 into matrixorigin:main Feb 26, 2026
23 of 24 checks passed
@mergify

mergify Bot commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

Rule: main


  • ✅ Entered queue — 2026-02-26 07:27 UTC
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-02-26 07:28 UTC · at adaee366450a74e7f11faac3513a3a9979e3cd05

This pull request spent 9 seconds in the queue, with no time running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • branch-protection-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI / SCA Test on Ubuntu/x86
  • 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 Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage

@mergify mergify Bot removed the queued label Feb 26, 2026
@ck89119
ck89119 deleted the feat/win_cume_dist branch February 26, 2026 07:31
mergify Bot pushed a commit that referenced this pull request Apr 28, 2026
- #23841 `ELT()` MySQL compatibility
- #23639 `AES_ENCRYPT()` / `AES_DECRYPT()`
- #23762 `CUME_DIST()` window function
- #23764 `PERCENT_RANK()` window function

### Notes on adaptation

* `CUME_DIST` and `PERCENT_RANK` did not cherry-pick cleanly because main's
`pkg/sql/colexec/aggexec` layer has been refactored substantially relative
to 3.0-dev (different signatures for `initAggResultWithFixedTypeResult`,
`marshalToBytes`, `unmarshalFromBytes`, plus new `SaveIntermediateResult*` /
`UnmarshalFromReader` interface methods and an `i64Slice` type).
These two executors were rewritten to follow 3.0-dev's existing
`singleWindowExec` pattern (`[][]int64` groups, 3-return `marshalToBytes`,
2-arg `unmarshalFromBytes`, no streaming serialization). Algorithms match
the originals exactly.

* The ELT cherry-pick brought in a copy of `func_binary_test.go` from main
containing tests for `TimeFormat` / `TimestampDiffDateString` / etc. that
don't exist on 3.0-dev. Those test blocks were removed; the ELT-specific
tests at the end of the file are preserved. Also added the `ELT` function
id and overload registration that the cherry-pick didn't include.

### Verification

```
go build ./...
go test -tags matrixone_test ./pkg/sql/colexec/aggexec/ \
./pkg/sql/colexec/window/ \
./pkg/sql/parsers/... \
./pkg/sql/plan/function/
```
all pass.

Fixes #24185

Approved by: @heni02, @iamlinjunhong, @ouyuanning, @aunjgr, @XuPeng-SH
fengttt pushed a commit to fengttt/matrixone that referenced this pull request May 7, 2026
Implement MySQL-compatible CUME_DIST() window function.

CUME_DIST() returns the cumulative distribution of a value within a partition.

**Formula**: (rows with values <= current row) / (total rows in partition)
**Return type**: DOUBLE, range (0, 1]

Approved by: @heni02, @ouyuanning, @iamlinjunhong

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/feature size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants