kll_sketch_get_n_bigint function
Applies to: Databricks Runtime 18.0 and later
Returns the number of items that have been added to an integer KLL sketch.
Syntax
kll_sketch_get_n_bigint ( sketch )
Arguments
sketch: ABINARYexpression containing a serialized integer KLL sketch.
Returns
A BIGINT representing the total count of items in the sketch.
Notes
- Returns the exact count of items added, not an estimate.
- Returns 0 for an empty sketch.
Examples
SQL
> WITH sketch_data AS (
SELECT kll_sketch_agg_bigint(value) AS sketch
FROM VALUES (1), (2), (3), (4), (5) AS T(value)
)
SELECT kll_sketch_get_n_bigint(sketch) FROM sketch_data
5
-- Check if sketch has sufficient data for reliable estimates
> WITH sketch_data AS (
SELECT kll_sketch_agg_bigint(value) AS sketch FROM my_table
)
SELECT
CASE
WHEN kll_sketch_get_n_bigint(sketch) >= 1000
THEN kll_sketch_get_quantile_bigint(sketch, 0.95)
ELSE NULL
END AS p95_if_sufficient_data
FROM sketch_data
[results]