6.21. Quantile Digest Functions
Presto implements the approx_percentile
function with the quantile digestdata structure. The underlying data structure, qdigest,is exposed as a data type in Presto, and can be created, queried and storedseparately from approx_percentile
.
Data Structures
A quantile digest is a data sketch which stores approximate percentileinformation. The presto type for this data structure is called qdigest
,and it takes a parameter which must be one of bigint
, double
orreal
which represent the set of numbers that may be ingested by theqdigest
. They may be merged without losing precision, and for storageand retrieval they may be cast to/from VARBINARY
.
Functions
merge
(qdigest) → qdigestMerges all input
qdigest
s into a singleqdigest
.valueat_quantile
(_qdigest(T), quantile) → TReturns the approximate percentile values from the quantile digest giventhe number
quantile
between 0 and 1.valuesat_quantiles
(_qdigest(T), quantiles) → TReturns the approximate percentile values as an array given the inputquantile digest and array of values between 0 and 1 whichrepresent the quantiles to return.
qdigestagg
(_x) → qdigest<[same as x]>Returns the
qdigest
which is composed of all input values ofx
.qdigestagg
(_x, w) → qdigest<[same as x]>Returns the
qdigest
which is composed of all input values ofx
usingthe per-item weightw
.qdigestagg
(_x, w, accuracy) → qdigest<[same as x]>- Returns the
qdigest
which is composed of all input values ofx
usingthe per-item weightw
and maximum error ofaccuracy
.accuracy
must be a value greater than zero and less than one, and it must be constantfor all input rows.