theta_sketch_estimate function
Applies to: Databricks SQL
Databricks Runtime 18.0 and above
Returns the estimated number of unique values from a Theta Sketch binary representation.
Syntax
theta_sketch_estimate ( sketch )
Arguments
- sketch: A Theta Sketch in binary format (such as from
theta_sketch_aggaggregate function,theta_union_aggaggregate function,theta_intersection_aggaggregate function,theta_unionfunction,theta_differencefunction, ortheta_intersectionfunction).
Returns
A LONG value representing the estimated distinct count.
Notes
- The result is rounded to the nearest integer.
- The estimate is probabilistic; accuracy depends on the
lgNomEntriesparameter used when creating the sketch.
Error messages
Examples
SQL
-- Get estimated distinct count from a sketch
> SELECT theta_sketch_estimate(theta_sketch_agg(col)) FROM VALUES (1), (1), (2), (2), (3) tab(col);
3