Skip to main content

kll_sketch_get_quantile_float function

Applies to: check marked yes Databricks Runtime 18.0 and later

Estimates the value at a given quantile rank (or multiple ranks) from a float KLL sketch.

Syntax

kll_sketch_get_quantile_float ( sketch, rank )

Arguments

  • sketch: A BINARY expression containing a serialized FLOAT KLL sketch.
  • rank: A DOUBLE expression or ARRAY<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 a FLOAT value representing the estimated quantile.
  • If rank is ARRAY<DOUBLE>: returns ARRAY<FLOAT> with quantile estimates for each rank.

Notes

  • Rank must be between 0.0 and 1.0 inclusive.
  • Returns NULL if 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_float(score) AS sketch
FROM VALUES (1.5), (2.3), (3.7) AS T(score)
)
SELECT kll_sketch_get_quantile_float(sketch, 0.5) FROM sketch_data
2.3