v.21.11New Features

Add exponentialMovingAverage aggregate function as a window function

Add aggregate function exponentialMovingAverage that can be used as window function. This closes #27511. #28914 (alexey-milovidov).
Added a new aggregate function exponentialMovingAverage that can be used as a window function to calculate exponential moving averages over data streams.

Why it matters

This feature addresses the need for efficient calculation of exponentially weighted moving averages within queries, enabling users to perform smoothing and trend analysis directly in ClickHouse without external processing.

How to use it

Use the exponentialMovingAverage function as a window function in SQL queries by specifying it in the SELECT clause with the OVER clause. For example:

SELECT
timestamp,
value,
exponentialMovingAverage(value) OVER (ORDER BY timestamp ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS ema
FROM table

This computes the exponential moving average of value ordered by timestamp.