quantilesTDigestWeighted
quantilesTDigestWeighted
Introduced in: v20.1.0
Computes multiple approximate quantiles of a numeric data sequence at different levels simultaneously using the t-digest algorithm. The function takes into account the weight of each sequence member.
This function is equivalent to quantileTDigestWeighted but allows computing multiple quantile levels in a single pass, which is more efficient than calling individual quantile functions.
The maximum error is 1%. Memory consumption is log(n), where n is a number of values.
The performance of the function is lower than performance of quantiles or quantilesTiming.
In terms of the ratio of State size to precision, this function is much better than quantiles.
The result depends on the order of running the query, and is nondeterministic.
Using quantilesTDigestWeighted is not recommended for tiny data sets and can lead to significant error.
In this case, consider possibility of using quantilesTDigest instead.
Syntax
Parameters
level— Levels of quantiles. One or more constant floating-point numbers from 0 to 1. We recommend usinglevelvalues in the range of[0.01, 0.99].Float*
Arguments
expr— Expression over the column values resulting in numeric data types,DateorDateTime.(U)Int*orFloat*orDateorDateTimeweight— Column with weights of sequence elements. Weight is a number of value occurrences.UInt*
Returned value
Array of approximate quantiles of the specified levels in the same order as the levels were specified. For Date and DateTime inputs the output format matches the input format. Array(Float32) or Array(Date) or Array(DateTime)
Examples
Computing multiple weighted quantiles with t-digest