kll_sketch_get_quantile_double function
Applies to: Databricks Runtime 18.0 and later
Estimates the value at a given quantile rank (or multiple ranks) from a double KLL sketch.
Syntax
kll_sketch_get_quantile_double ( sketch, rank )
Arguments
sketch: ABINARYexpression containing a serializedDOUBLEKLL sketch.rank: ADOUBLEexpression orARRAY<DOUBLE>of quantile ranks between 0.0 and 1.0, where:- 0.0 is the minimum,
- 0.5 is the median, and
- 1.0 is the maximum.
Returns
- If rank is
DOUBLE: returns aDOUBLEvalue representing the estimated quantile. - If rank is
ARRAY<DOUBLE>: returnsARRAY<DOUBLE>with quantile estimates for each rank.
Notes
- Rank must be between 0.0 and 1.0 inclusive.
- Returns
NULLif the sketch is empty. - Common quantiles: 0.25 (Q1), 0.5 (median), 0.75 (Q3), 0.95 (P95), 0.99 (P99).
Examples
SQL
> WITH sketch_data AS (
SELECT kll_sketch_agg_double(value) AS sketch
FROM VALUES (1.23), (2.34), (3.45) AS T(value)
)
SELECT kll_sketch_get_quantile_double(sketch, array(0.25, 0.75)) FROM sketch_data
[1.23, 3.45]