Skip to content

branch-4.1: [feature](be/fe) Add exponential_moving_average aggregate function #63499#63814

Merged
yiguolei merged 1 commit into
branch-4.1from
auto-pick-63499-branch-4.1
May 29, 2026
Merged

branch-4.1: [feature](be/fe) Add exponential_moving_average aggregate function #63499#63814
yiguolei merged 1 commit into
branch-4.1from
auto-pick-63499-branch-4.1

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Cherry-picked from #63499

…63499)

    Problem Summary:
    Doris lacked an exponential moving average aggregate function. This
implements `exponential_moving_average(half_decay, value, time)` ported
    from ClickHouse's ExponentialMovingAverage aggregate.

    Algorithm:
    - State stores (value, time, half_decay) as doubles.
    - On add(): scale existing value to the new timestamp via
`2^(-dt/half_decay)`, then accumulate. Store half_decay in state so
      it is available during merge().
    - On merge(): advance both states to the later timestamp, then sum.
      This is commutative and associative, so row order doesn't matter.
    - Result: `value * (1 - 2^(-1/half_decay))` (normalised by sum of
      weights).

    Changes:
- BE: `aggregate_function_ema.h/cpp` — state struct + function class,
      registered in `aggregate_function_simple_factory.cpp`.
- FE: `ExponentialMovingAverage.java` — 3-arg DOUBLE signature, visitor
      method added to `AggregateFunctionVisitor`, registered in
      `BuiltinAggregateFunctions`.
    - Regression test: `query_p0/aggregate/exponential_moving_average/`.

    ### Release note

New aggregate function `exponential_moving_average(half_decay, value,
time)`
computes the exponential moving average over a stream of (value, time)
    pairs with the given half-decay parameter.

    ### Check List (For Author)

- Test: Regression test added
(query_p0/aggregate/exponential_moving_average)
    - Behavior changed: No (new function)
- Does this need documentation:
[docs](apache/doris-website#3726)

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot requested a review from yiguolei as a code owner May 28, 2026 07:57
@hello-stephen
Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@hello-stephen
Copy link
Copy Markdown
Contributor

run buildall

@hello-stephen
Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 3.23% (1/31) 🎉
Increment coverage report
Complete coverage report

@hello-stephen
Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 45.00% (18/40) 🎉
Increment coverage report
Complete coverage report

@yiguolei yiguolei merged commit 361bfd0 into branch-4.1 May 29, 2026
28 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants