rollup()

rollup(
    sketch uddsketch
) RETURNS UddSketch
rollup(
    digest tdigest
) 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() function uses the UddSketch algorithm, rollup returns the UddSketch data structure for use in further calls.

When you use the percentile_agg or UddSketch aggregates, the rollup function does not introduce additional errors compared to calculating the estimator directly, however, using rollup with tdigest can introduce additional errors compared to calculating the estimator directly on the underlying data.

Sample usage

Re-aggregate an hourly continuous aggregate into daily buckets, the usage with uddsketch & tdigest is exactly the same:

CREATE MATERIALIZED VIEW foo_hourly
WITH (timescaledb.continuous)
AS SELECT
    time_bucket('1 h'::interval, ts) as bucket,
    percentile_agg(value) as pct_agg
FROM foo
GROUP BY 1;

SELECT
    time_bucket('1 day'::interval, bucket) as bucket,
    approx_percentile(0.95, rollup(pct_agg)) as p95,
    approx_percentile(0.99, rollup(pct_agg)) as p99
FROM foo_hourly
GROUP BY 1;

Found an issue on this page?

Report an issue!

Related Content