- Categories:
Aggregate functions (Cardinality Estimation) , Window function syntax and usage
DATASKETCHES_HLL_ESTIMATE¶
Returns the cardinality estimate for the given sketch.
This function is a version of the HLL HyperLogLog function that can read binary sketches in the format used by Apache DataSketches. For more information, see the Apache DataSketches documentation.
A sketch produced by the DATASKETCHES_HLL_COMBINE function can be used to compute a cardinality estimate using the DATASKETCHES_HLL_ESTIMATE function.
Syntax¶
Arguments¶
binary_sketchAn expression that contains sketch information in binary format.
Returns¶
The function returns a value of type DOUBLE.
If the input is empty, the output is 0.0.
Note
This function returns a value of a different type than the HLL_ESTIMATE function, which returns an INTEGER value.
Examples¶
Create a table and insert values:
The following examples use the data in the table.
Return the cardinality estimate for accumulated binary sketches¶
The following example performs the following actions:
The DATASKETCHES_HLL_ACCUMULATE function creates two binary sketches for the data in column
v, grouped by the values1and2in columngThe DATASKETCHES_HLL_ESTIMATE function returns the cardinality estimate for each accumulated sketch.
You can see values of the accumulated sketches in the example in DATASKETCHES_HLL_ACCUMULATE.
Return the cardinality estimate for combined binary sketches¶
The following example performs the following actions:
The DATASKETCHES_HLL_ACCUMULATE function creates two binary sketches for the data in column
v, grouped by the values1and2in columngThe DATASKETCHES_HLL_COMBINE function combines these binary sketches to unify them.
The DATASKETCHES_HLL_ESTIMATE function returns the cardinality estimate for the unified sketch.
You can see value of the combined sketches in the example in DATASKETCHES_HLL_COMBINE.