Skip to content

[Feature Request]: exponential-weighted statistics with explicit decay and NULL policies #29945

Closed

Description

@dengn

Why this is needed

Online anomaly baselines and adaptive volatility need gradual forgetting rather than a hard cutoff. Irregular event-time decay and missing samples require explicit half-life/ignoreNA behavior; a fixed ROWS average is not equivalent.

Requested behavior and scope

Provide exponentially weighted mean/variance/std/covariance/correlation with declared alpha/com/span/half-life, adjust, ignoreNA and initialization policies. The verified simple profile is alpha=0.5, adjust=False, no missing samples, first-sample initialization: values 1,2,3,4 produce means 1,1.5,2.25,3.125. A finite historical self-join can emulate that profile, but does not establish a native incremental-state API or performance parity.

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 ewmMean(CAST(1 AS DOUBLE),3) result;

Actual MO result, reproduced 3/3:

(20105, "not supported: function or operator 'ewmmean'")

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
ewmMean_entry rejected 3/3 Entry resolution only; no invented engine result
ewmVar_entry rejected 3/3 Entry resolution only; no invented engine result
ewmStd_entry rejected 3/3 Entry resolution only; no invented engine result
ewmCov_entry rejected 3/3 Entry resolution only; no invented engine result
ewmCorr_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,CAST(1 AS DOUBLE) v
  UNION ALL SELECT 2,2
  UNION ALL SELECT 3,3
  UNION ALL SELECT 4,4) fixture) SELECT a.id,SUM(b.v*CASE WHEN b.id=1 THEN POWER(CAST(0.5 AS DOUBLE),a.id-1) ELSE CAST(0.5 AS DOUBLE)*POWER(CAST(0.5 AS DOUBLE),a.id-b.id) END) result FROM raw a JOIN raw b ON b.id<=a.id GROUP BY a.id ORDER BY a.id;
Control Verified values
alpha_half_adjust_false_control 1, 1.5, 2.25, 3.125

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.

Reference

https://docs.dolphindb.com/en/Functions/e/ewmMean.html

Activity

  1. XuPeng-SH commented on Oct 12, 2026

    @XuPeng-SH
    Contributor

    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.

  2. added this to the Backlog milestone on Oct 12, 2026
  3. self-assigned this
    on Oct 12, 2026
  4. added
    severity/s0
    ai-easy
    and removed on Oct 23, 2026
  5. gouhongshen commented on Oct 31, 2026

    @gouhongshen
    Contributor

    PR #31941 is trying to fix this issue.

  6. gouhongshen commented on Oct 31, 2026

    @gouhongshen
    Contributor

    PR #31941 has merged and is awaiting manual validation. The issue remains open.

  7. XuPeng-SH commented on Oct 31, 2026

    @XuPeng-SH
    Contributor

    QA 交接(待验证,不代表验收通过)

    关联 PR:#31941,已合入 main;merge SHA:c699e15c016495276f8fee224fc14316740de059。

    已核对本 issue 全部评论及 PR/设计范围:五个 EWM window 函数、alpha / event-time half-life、adjust、ignoreNA、minPeriods 与初始化已有实现。com/span/行 half-life 通过设计中明确的 alpha 常量换算表达;不是命名参数 API。旧版本入口缺失及旧 head 的 CASE/IFNULL 常量拒绝不能直接作为合入版本反例;后者已修复并获后续评审确认,目前未发现仍适用的已验证反例或未完开发 follow-up。

    真实验证证据(远端作者/评审报告,不是本轮本地实测):作者报告配置/binder 回归及完整 EWM SQL fixture 377/377;后续评审报告真实 MySQL 377 条、prepared CASE 重复执行与 event-time ordering controls 通过,且旧 CASE/IFNULL finding 已闭环。历史数值/lifecycle/race 证据保留其原有适用范围。

    请 @Ariznawlll 在合入 main 上独立回归:

    • 五个函数的完整值、NULL 位及行对齐;alpha=.5、adjust=false 的 1/1.5/2.25/3.125 基准。
    • 分区、并列顺序、全 NULL、ignoreNA/adjust 组合、不规则 event-time、极值/亚正规数、minPeriods 整数边界与错误后会话恢复。
    • CASE/IFNULL/marker 参数跨 prepared 重复执行、缓存隔离及取消/Reset/复用。
      边界:仅 window OVER;population variance;显式有限移动 frame、多键或降序 event-time 不在 v1 支持范围,应校验清晰拒绝;不要把这些边界写成全参数兼容或性能验收。本轮未运行本地测试、未重跑全量 CI/多 CN、混合版本或生产规模性能,相关覆盖仍交 QA。无需因本次转测自动要求 4.2 backport。
  8. Ariznawlll commented on Oct 31, 2026

    @Ariznawlll
    Collaborator

    测试补充

    结论

    测试不通过。已完成本次功能范围的黑盒和白盒验证;发现的预编译嵌套参数问题已单独提交为 #31952,后续修复及回归在该 bug 中跟踪。按约定,本功能 issue 在记录测试结果后关闭。

    关键证据

    • 测试版本为官方 main@ae40f12a647880a63466de32a9f507c2c72dca0b,源码构建见 构建记录。SQL 黑盒在隔离的 Linux/amd64 Docker 模拟环境执行,分别覆盖 1 CN / 1 TN 和同进程 2 CN / 1 TN;两个实例均无 OOM 或重启,测试库已清理。
    • 五个窗口函数 ewmMean、ewmVar、ewmStd、ewmCov、ewmCorr 均校验结果和 NULL:完整 SQL 用例连续 3 轮,每轮 377/377;独立分数计算对照 alpha=0.5 的 180 组全通过。alpha=0.25 和 0.75 的各 180 组在与合入提交源码树一致的构建上通过。基础序列 1,2,3,4、alpha=0.5、adjust=false 的均值为 1,1.5,2.25,3.125。
    • 覆盖分区、并列键、全 NULL、adjust / ignoreNA、minPeriods、不规则 event-time half-life、极值和亚正规数。独立双 CN 场景中,两个入口各 3 轮逐行核对 12,000 行和五个结果列,行序、值及结果哈希一致。
    • 异常场景覆盖无 OVER、非法 alpha / half-life / minPeriods、非常量策略、不支持的有限移动窗口以及 event-time 降序和多排序键;检查错误后会话继续可用。文本和二进制预编译覆盖参数变化、非法值后恢复,以及已发现的 CASE / IFNULL 嵌套参数缺陷。
    • 执行中 KILL QUERY 后,同一连接和同一预编译语句重新执行 10/10 正确;二进制语句 RESET 与复用 10/10 正确。两连接不同参数交替执行 20 次正确。
    • 白盒在相同 main 源码上执行 EWM 核心算法全包测试、race 测试,覆盖 204 条数值 oracle;切片续算和合并阶段取消的 race 定向用例重复 20 次通过。解析、绑定、配置、窗口算子和前端的定向包测试见 Linux CI 记录。

    待解决点

    • [Bug]: EWM rejects numeric prepared parameters nested in IFNULL or CASE #31952:五个 EWM 函数在数值 marker 嵌套于 IFNULL 时均 3/3 在预编译阶段报 20203;CASE 形式同样复现,显式 CAST 对照通过。修复和回归由该 bug 继续跟踪。
    • 本轮双 CN 为本地单进程环境,未覆盖 TKE 多节点、混合版本和生产规模性能;不据此宣称这些场景或 pandas 全参数语义已验收。设计范围为 window OVER、总体方差;com / span / 行 half-life 通过 alpha 常量换算,不是命名参数 API。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-easykind/featureseverity/s0

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions