rollup(CounterSummary)
2. rollup(
4. cs CounterSummary
6. ) RETURNS CounterSummary
An aggregate to compute a combined CounterSummary from a series of non-overlapping CounterSummaries. Non-disjointed CounterSummaries cause errors.
For more information about counter aggregation functions, see the hyperfunctions documentation.
Required arguments
| Name | Type | Description |
|---|---|---|
cs |
CounterSummary | The input CounterSummary from a previous counter_agg (point form) call, often from a continuous aggregate |
Returns
| Column | Type | Description |
|---|---|---|
counter_agg |
CounterSummary | A CounterSummary object that can be passed to accessor functions or other objects in the counter aggregate API |
Sample usage
2. WITH t as (
4. SELECT
6. date_trunc('day', ts) as dt,
8. counter_agg(ts, val) AS counter_summary -- get a time weight summary
10. FROM foo
12. WHERE id = 'bar'
14. GROUP BY date_trunc('day')
16. ), q as (
18. SELECT rollup(counter_summary) AS full_cs -- do a second level of aggregation to get the full CounterSummary
20. FROM t
22. )
24. SELECT
26. dt,
28. delta(counter_summary), -- extract the delta from the CounterSummary
30. delta(counter_summary) / (SELECT delta(full_cs) FROM q LIMIT 1) as normalized -- get the fraction of the delta that happened each day compared to the full change of the counter
32. FROM t;
