kll_sketch_get_rank_double function
Applies to: Databricks Runtime 18.0 and later
Estimates the normalized rank (0.0 to 1.0) of a given value in a double KLL sketch.
Syntax
kll_sketch_get_rank_double ( sketch, value )
Arguments
sketch: ABINARYexpression containing a serializedDOUBLEKLL sketch.value: ADOUBLEexpression orARRAY<DOUBLE>of values to find ranks for.
Returns
- If value is
DOUBLE: returns aDOUBLEbetween 0.0 and 1.0 representing the normalized rank. - If value is
ARRAY<DOUBLE>: returnsARRAY<DOUBLE>with ranks for each value.
Notes
- The rank represents the fraction of values in the sketch that are less than or equal to the given value.
- Returns 0.0 if all sketch values are greater than the input value.
- Returns 1.0 if all sketch values are less than or equal to the input value.
Examples
SQL
> WITH sketch_data AS (
SELECT kll_sketch_agg_double(value) AS sketch
FROM VALUES (1.0), (2.0), (3.0) AS T(value)
)
SELECT kll_sketch_get_rank_double(sketch, array(1.5, 2.5)) FROM sketch_data
[0.33, 0.66]