interpolated_delta()

Calculate the change in a counter over a time period. Data points at the exact boundaries of the time period aren’t needed. The function interpolates the counter values at the boundaries from adjacent CounterSummaries if needed.

2. interpolated_delta(

4. summary CounterSummary,

6. start TIMESTAMPTZ,

8. interval INTERVAL,

10. prev CounterSummary,

12. next CounterSummary

14. ) RETURNS DOUBLE PRECISION

For more information about counter aggregation functions, see the hyperfunctions documentation.

Required arguments

Name Type Description
summary CounterSummary The input CounterSummary from a counter_agg call
start TIMESTAMPTZ The start of the interval which the delta should be computed over (if there is a preceeding point)
interval INTERVAL The length of the interval which the delta should cover

Optional arguments

Name Type Description
prev CounterSummary The CounterSummary from the prior interval, used to interpolate the value at start. If NULL, the first timestamp in summary is used as the start of the interval.
next CounterSummary The CounterSummary from the following interval, used to interpolate the value at start + interval. If NULL, the last timestamp in summary is used as the end of the interval.

Returns

Name Type Description
interpolated_delta DOUBLE PRECISION The delta between the first and last points of the time interval. If exact values are missing in the raw data for the first and last points, these values are interpolated linearly from the neighboring CounterSummaries

Sample usage

2. SELECT

4. id,

6. bucket,

8. interpolated_delta(

10. summary,

12. bucket,

14. '15 min',

16. LAG(summary) OVER (PARTITION BY id ORDER by bucket),

18. LEAD(summary) OVER (PARTITION BY id ORDER by bucket)

20. )

22. FROM (

24. SELECT

26. id,

28. time_bucket('15 min'::interval, ts) AS bucket,

30. counter_agg(ts, val) AS summary

32. FROM foo

34. GROUP BY id, time_bucket('15 min'::interval, ts)

36. ) t