Skip to main content
Skip to main content

quantilesTimingWeighted

Same as quantileTimingWeighted, but accept multiple parameters with quantile levels and return an Array filled with many values of that quantiles.

Example

Input table:

┌─response_time─┬─weight─┐
│            68 │      1 │
│           104 │      2 │
│           112 │      3 │
│           126 │      2 │
│           138 │      1 │
│           162 │      1 │
└───────────────┴────────┘

Query:

SELECT quantilesTimingWeighted(0,5, 0.99)(response_time, weight) FROM t

Result:

┌─quantilesTimingWeighted(0.5, 0.99)(response_time, weight)─┐
│ [112,162]                                                 │
└───────────────────────────────────────────────────────────┘

See Also

quantilesTimingWeighted

Introduced in: v1.1

Computes multiple quantiles of a numeric data sequence at different levels simultaneously with determined precision, taking into account the weight of each sequence member.

This function is equivalent to quantileTimingWeighted but allows computing multiple quantile levels in a single pass, which is more efficient than calling individual quantile functions.

The result is deterministic (it does not depend on the query processing order). The function is optimized for working with sequences which describe distributions like loading web pages times or backend response times.

Accuracy

The calculation is accurate if:

  • Total number of values does not exceed 5670.
  • Total number of values exceeds 5670, but the page loading time is less than 1024ms.

Otherwise, the result of the calculation is rounded to the nearest multiple of 16 ms.

Note

For calculating page loading time quantiles, this function is more effective and accurate than quantiles.

Syntax

quantilesTimingWeighted(level1, level2, ...)(expr, weight)

Parameters

  • level — Levels of quantiles. One or more constant floating-point numbers from 0 to 1. We recommend using level values in the range of [0.01, 0.99]. Float*

Arguments

  • expr — Expression over a column values returning a Float*-type number. If negative values are passed to the function, the behavior is undefined. If the value is greater than 30,000 (a page loading time of more than 30 seconds), it is assumed to be 30,000. Float*
  • weight — Column with weights of sequence elements. Weight is a number of value occurrences. UInt*

Returned value

Array of quantiles of the specified levels in the same order as the levels were specified. Array(Float32)

Examples

Computing multiple weighted timing quantiles

SELECT quantilesTimingWeighted(0.5, 0.99)(response_time, weight) FROM t;
┌─quantilesTimingWeighted(0.5, 0.99)(response_time, weight)─┐
│ [112, 162]                                                │
└───────────────────────────────────────────────────────────┘