メインコンテンツまでスキップ

kll_sketch_get_rank_float function

Applies to: check marked yes Databricks Runtime 18.0 and later

Estimates the normalized rank (0.0 to 1.0) of a given value in a float KLL sketch.

Syntax

kll_sketch_get_rank_float ( sketch, value )

Arguments

  • sketch: A BINARY expression containing a serialized FLOAT KLL sketch.
  • value: A FLOAT expression or ARRAY<FLOAT> of values to find ranks for.

Returns

  • If value is FLOAT: returns a DOUBLE between 0.0 and 1.0 representing the normalized rank.
  • If value is ARRAY<FLOAT>: returns ARRAY<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_float(score) AS sketch
FROM VALUES (1.5), (2.3), (3.7) AS T(score)
)
SELECT kll_sketch_get_rank_float(sketch, 2.5) FROM sketch_data
0.66