v.22.6New Feature

Added nonNegativeDerivative Window Function

Added a new window function nonNegativeDerivative(metric_column, timestamp_column[, INTERVAL x SECOND]). #37628 (Andrey Zvonov).
Introduced a new window function nonNegativeDerivative(metric_column, timestamp_column[, INTERVAL x SECOND]) in ClickHouse.

Why it matters

This feature addresses the need to calculate the derivative of a metric over time while ensuring the result is never negative, which is useful for analyzing time series data where decreases in values are not meaningful or should be treated as zero, such as counters or cumulative metrics.

How to use it

Use the nonNegativeDerivative window function by passing the metric column and the corresponding timestamp column as arguments. Optionally, specify an interval to define the time steps for derivative calculation. For example:

SELECT nonNegativeDerivative(metric, timestamp, INTERVAL 1 SECOND) OVER (ORDER BY timestamp) FROM table