branch-4.1: [feature](be/fe) Add exponential_moving_average aggregate function #63499#63814
Merged
Merged
Conversation
…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>
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
|
run buildall |
Contributor
FE UT Coverage ReportIncrement line coverage |
Contributor
FE Regression Coverage ReportIncrement line coverage |
yiguolei
approved these changes
May 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cherry-picked from #63499