rollup()

  1. rollup(
  2. sketch uddsketch
  3. ) RETURNS UddSketch
  1. rollup(
  2. digest tdigest
  3. ) RETURNS tdigest

This combines multiple outputs from the percentile_agg() function (or either uddsketch() or tdigest()). This is especially useful for re-aggregation in a continuous aggregate. For example, bucketing by a larger time_bucket(), or re-grouping on other dimensions included in an aggregation.

Required arguments

NameTypeDescription
sketch / digestUddSketch or tdigestThe already constructed data structure from a previous percentile_agg, uddsketch, or tdigest call

Returns

ColumnTypeDescription
rollupUddSketch / tdigestA UddSketch or tdigest object which may be passed to further APIs

Because the percentile_agg()](/hyperfunctions/percentile-approximation/aggregation-methods/percentile_agg/) function uses the UddSketch algorithm, rollup returns the UddSketch data structure for use in further calls.

When using the percentile_agg or UddSketch aggregates, the rollup function will not introduce additional error (compared to calculating the estimator directly), however, using rollup with tdigest may introduce additional error compared to calculating the estimator directly on the underlying data.

Sample usage

Here, we re-aggregate an hourly continuous aggregate into daily buckets, the usage with uddsketch & tdigest is analogous:

  1. CREATE MATERIALIZED VIEW foo_hourly
  2. WITH (timescaledb.continuous)
  3. AS SELECT
  4. time_bucket('1 h'::interval, ts) as bucket,
  5. percentile_agg(value) as pct_agg
  6. FROM foo
  7. GROUP BY 1;
  8. SELECT
  9. time_bucket('1 day'::interval, bucket) as bucket,
  10. approx_percentile(0.95, rollup(pct_agg)) as p95,
  11. approx_percentile(0.99, rollup(pct_agg)) as p99
  12. FROM foo_hourly
  13. GROUP BY 1;