Skip to content

tdigest()

Aggregate data in a `tdigest` for further calculation of percentile estimates

Since 1.0.0

This is the first step for calculating approximate percentiles with the tdigest algorithm. Use tdigest to create an intermediate aggregate from your raw data. This intermediate form can then be used by one or more accessors in this group to compute final results.

Optionally, multiple such intermediate aggregate objects can be combined using rollup() before an accessor is applied.

Given a table called samples, with a column called data, build a tdigest using the data column. Use a size of 100 for the approximation.

SELECT tdigest(100, data) FROM samples;

The syntax is:

tdigest(
size INTEGER,
value DOUBLE PRECISION
) RETURNS TDigest
NameTypeDefaultRequiredDescription
sizeINTEGER-✔A digest built in one pass holds at most size buckets; one built by rollup() or by a parallel plan can hold one more. Increasing size provides more accurate quantile estimates, but requires more memory
valueDOUBLE PRECISION-✔Column of values to aggregate for the tdigest object
ColumnTypeDescription
tdigestTDigestA percentile estimator object created to calculate percentiles using the tdigest algorithm