Repository navigation
Description
Why this is needed
An alert often asks how unusual the current observation is relative to the most recent observations. Partition-wide rank changes with the entire history and does not answer that local question; assigning a ROWS clause to RANK does not make it frame-local.
Requested behavior and scope
Provide moving/time/cumulative local-rank operators or a canonical SQL equivalent with documented competition/dense/average/percentile conventions and direction. The verified business profile is 1-based ascending competition rank of the current non-NULL value in the last three physical rows, returning NULL when the current value is NULL. This is a declared profile, not an assertion about all DolphinDB default rank conventions.
Tested revision / existing issue check
- MatrixOne commit:
23d8f61252f3017dff218b530817a240206fd762. - Existing issues were searched before filing; related requests/closed fixes are distinguished above.
- All data below is synthetic. The probe is read-only and requires no persisted tables.
Executable unsupported case
SELECT mrank(CAST(1 AS DOUBLE),3) result;Actual MO result, reproduced 3/3:
(20105, "not supported: function or operator 'mrank'")
This probe checks entry-name availability only. A rejection does not establish that the business calculation is impossible or that this is a valid DolphinDB script signature. The requested mathematical operation is defined above and checked by the independent profile below.
Additional actually executed cases
Each listed rejection was executed three times on the same synthetic fixture.
| Case | MO result | Declared expected values / scope |
|---|---|---|
mrank_entry |
rejected 3/3 | Entry resolution only; no invented engine result |
tmrank_entry |
rejected 3/3 | Entry resolution only; no invented engine result |
cumrank_entry |
rejected 3/3 | Entry resolution only; no invented engine result |
Working SQL control / alternative
The following control was executed 3/3 and its complete output values were checked, not merely execution success:
WITH raw AS (SELECT *
FROM (
SELECT 1 id,1 gid,0 tick,CAST(NULL AS DOUBLE) v,CAST(2.0 AS DOUBLE) y,CAST(1.0 AS DOUBLE) w,1 flag
UNION ALL SELECT 2 id,1 gid,0 tick,CAST(2.0 AS DOUBLE) v,CAST(4.0 AS DOUBLE) y,CAST(2.0 AS DOUBLE) w,0 flag
UNION ALL SELECT 3 id,1 gid,1 tick,CAST(4.0 AS DOUBLE) v,CAST(3.0 AS DOUBLE) y,CAST(1.0 AS DOUBLE) w,1 flag
UNION ALL SELECT 4 id,1 gid,3 tick,CAST(4.0 AS DOUBLE) v,CAST(7.0 AS DOUBLE) y,CAST(3.0 AS DOUBLE) w,1 flag
UNION ALL SELECT 5 id,1 gid,3 tick,CAST(NULL AS DOUBLE) v,CAST(5.0 AS DOUBLE) y,CAST(1.0 AS DOUBLE) w,0 flag
UNION ALL SELECT 6 id,1 gid,8 tick,CAST(-1.0 AS DOUBLE) v,CAST(8.0 AS DOUBLE) y,CAST(2.0 AS DOUBLE) w,1 flag) fixture) SELECT a.id,CASE WHEN a.v IS NULL THEN NULL ELSE 1+SUM(CASE WHEN b.v<a.v THEN 1 ELSE 0 END) END result FROM raw a JOIN raw b ON b.id BETWEEN a.id-2 AND a.id GROUP BY a.id,a.v ORDER BY a.id;| Control | Verified values |
|---|---|
local_competition_rank_control |
NULL, 1, 2, 2, NULL, 1 |
Acceptance / regression coverage
Retain the self-contained fixture and assert complete values, NULL bits and row alignment. Add partitions, ties, empty/all-NULL frames, frame-entry/exit and type boundaries appropriate to this operator. Validate named/API availability separately from mathematical rewrites. Benchmark any claimed state/performance advantage with identical data and correctness rules; no speedup is asserted by these small tests.
Subsequent SELECT 1 succeeded after the test matrix. DolphinDB references are official documentation; no DolphinDB runtime or all-parameter parity is claimed.
Activity
XuPeng-SH commentedon Oct 12, 2026
Triage decision: defer.
Reason: this is a specialized window/time-series capability. The report establishes a syntax or API gap, but does not show a confirmed customer blocker or near-term roadmap commitment. The umbrella report also notes that many profiles can be composed from existing SQL and does not provide a native-performance comparison.
Promote when a concrete customer workload or roadmap commitment is identified and correctness/performance acceptance criteria are agreed.
gouhongshen commentedon Oct 24, 2026
PR #31020 is trying to fix this issue.
gouhongshen commentedon Oct 24, 2026
PR #31020 has merged and is awaiting manual validation. The issue remains open.
XuPeng-SH commentedon Oct 25, 2026
Manual validation of merged PR #31020 on current main:
ac4ec315877cfc95fc5464bd81b081489f75f747(merge SHA); built service binary SHA-256:d90908dd90af8f0717a07dbeedbaa8d8e7b394bbbdc05404b337782a3d05516e.window_local_rank.sqlBVT completed 181 statements: 54 result sets matched the paired.resultexactly and 39 expected errors matched (0 mismatches).mrank(v,3) OVER (ORDER BY id)profile returnedNULL,1,2,2,NULL,1, matching the independent self-join SQL control and Python oracle. The 354-row independent challenge coveredmrank/cumrank/tmrank, ties, NULLs, partitions, width and type boundaries, timestamp and calendar-month cutoffs, DECIMAL256, and prepared-statement error recovery. Two concurrent SQL sessions also matched the seeded oracle.go test ./pkg/sql/colexec/window -run '^(TestLocalRank.*|TestValidateIntervalFrameBoundsCoversTmrankWidths)$' -count=1 -v -timeout=18m(exit 0), including cancellation and memory-balance cases.This validates the declared local-rank profile and tested SQL/operator behavior on one isolated local CN. It does not establish a performance advantage, multi-CN behavior, or runtime parity with DolphinDB.
Ariznawlll commentedon Oct 26, 2026
测试版本
5fe08a3307e246e1ab9951ab690b50557af0f509;LOG/TN/CN 在同一进程、单 CN、独立数据目录及 SQL 端口 6201。测试时官方main为4769417cdce5531c9771644eca49f1e71d8f654c;本地源码少一个与本功能无关的 SHOW/ALTER 默认值及 dump 提交,不把本轮称作该最新 SHA 的实测。309a0ca650e0c55e90292767fd61e4976818d66d对已合入 SQL/golden 执行实际结果比对。原问题验证
原 issue 的六行窗口竞争排名
mrank(v,3) OVER (ORDER BY id)得到NULL,1,2,2,NULL,1;同脚本的独立 self-join + 聚合 SQL 对照给出相同结果。它验证“最近三条物理行里的当前值排名”,不拿分区全历史RANK()冒充局部排名。Happy Path 覆盖
window_local_rank.sql:181 条语句,181 成功、0 失败、0 异常、0 跳过;与配套.result全量比对。mrank的宽度 1/2/3、宽度超过分区、分区重置、NULL 当前值及 ties;cumrank与宽窗口的等价对照。时间窗tmrank覆盖 1 DAY、十进制1.5 DAY与字符串'1.5' DAY的不同边界、月末日历截断、同时间戳 peers 和 NULL 键。LIMIT 0,核对错误后的可复用性和 40 小时时间边界。Unhappy Path 覆盖
mrank宽度 0、负数、NULL、非整数/错误类型及缺参数;tmrank非时间排序键、列引用宽度、负数/NULL/溢出 interval、额外参数、显式 frame,均与预期错误比对。RAND()、SLEEP()和控制函数作为时间窗宽度在绑定阶段被拒绝;溢出宽度在有行、空输入、LIMIT 0和重复执行下保持相同拒绝。错误后同一 prepared handle 以合法参数再次得到正确结果。OVER的入口按窗口语法拒绝;mrank/cumrank/tmrank仍可作为普通标识符使用。脚本恢复会话时区并删除隔离测试库。白盒验证
本轮未重新运行 Go UT 或 race;此前研发的局部 rank operator 聚焦测试与独立 354 行 oracle 见已有验证评论,不计入本轮 181 条黑盒结果。
回归测试
实现 PR #31020 已合入;本轮复跑 SQL 用例 与配套 golden。本次没有新增回归代码或 PR。
测试证据
/private/tmp/qa-three-features-local.TrLbxB/rank_test.log,摘要TOTAL=181, SUCCESS=181, FAILED=0, ABNORAML=0, SUCCESS RATE=100%。测试结论
测试通过。
Ariznawlll commentedon Oct 26, 2026
测试补充:已执行验证与回归跟踪
测试版本
2026-10-26,本地 MatrixOne 源码
5fe08a3307e246e1ab9951ab690b50557af0f509。原 SQL/golden 在隔离单 CN 上验证;新增 MOTR 在同一进程内两个直连 CN 服务、共享 LOG/TN 环境复跑,不等同于 TKE 独立 CN Pod 验证。原问题验证
window_local_rank.sql共 181/181 条成功,0 失败、0 异常、0 跳过,结果与 golden 全量一致。原文六行mrank(v,3)结果为NULL,1,2,2,NULL,1,与独立 self-join/聚合对照相同,验证的是局部物理行窗口,不是分区全历史 RANK。Happy Path 覆盖
3→1→0(预期错误)→3,核对结果、元数据及错误后连接/语句复用。mrank/cumrank/tmrank 使用独立逐行 oracle。Unhappy Path 覆盖
非法宽度、NULL/负数/溢出 interval、错误类型、参数数量、非时间键、显式 frame,以及 RAND/SLEEP 等不允许的表达式,均验证预期拒绝;包含空输入、LIMIT 0 和错误后的合法重绑定。新增用例与 #29949 一起执行 MOTR
--repeat 3,本地共 6/6 通过。白盒验证
本次未新增或重跑 Go UT/race;此前 operator 聚焦测试及独立 354 行 oracle 见已有验证记录,不计入本轮黑盒统计。
回归测试
issue_29947_local_rank_binary.go及启动脚本。测试证据
本地完整 SQL 验证记录及 MOTR 用例与本地复跑摘要。
按本次确认的验收安排,先关闭本 feature;计划于 2026-10-27 执行的 TKE 回归仍为待执行,不计入已通过范围。未宣称 DolphinDB 全部默认行为/性能一致或长期稳定性已验证。下述结论仅针对上述已执行的本地功能验证。
测试结论
测试通过。
Improve local rank performance and clean up follow-up debt (#31516)