- Categories:
Aggregate functions (Cardinality Estimation) , Window functions (Cardinality Estimation)
HLL_ESTIMATE¶
Returns the cardinality estimate for the given HyperLogLog state.
A HyperLogLog state produced by HLL_ACCUMULATE and HLL_COMBINE can be used to compute a cardinality estimate using the HLL_ESTIMATE function.
Thus, HLL_ESTIMATE(HLL_ACCUMULATE(…)) is equivalent to HLL(…).
- See also:
Syntax¶
Aggregate function
Window function
For details about the OVER clause, see Window function syntax and usage.
Arguments¶
stateAn expression that contains state information generated by a call to HLL_ACCUMULATE or HLL_COMBINE.
Usage notes¶
This function can be used as an aggregate function or a window function.
Examples¶
This example shows how to use the three related functions HLL_ACCUMULATE, HLL_ESTIMATE, and HLL_COMBINE.
Create a simple table and data:
Create a table that contains the “state” that represents the current
approximate cardinality information for the table named sequence_demo:
Now create a second table and add data. (In a more realistic situation, the user could have loaded more data into the first table and divided the data into non-overlapping sets based on the time that the data was loaded.)
Get the “state” information for just the new data.
Combine the “state” information for the two batches of rows:
Get the approximate cardinality of the combined set of rows: