- Categories:
Aggregate functions (Cardinality Estimation) , Window functions (Cardinality Estimation)
HLL_ACCUMULATE¶
Returns the HyperLogLog state at the end of aggregation.
For more information about HyperLogLog, see Estimating the Number of Distinct Values.
HLL discards its intermediate state when the final cardinality estimate is returned. In advanced use cases, such as incremental cardinality estimation during bulk loading, one may want to keep the intermediate state. The intermediate state can later be combined (merged) with other intermediate states, or can be exported to external tools.
In contrast to HLL, HLL_ACCUMULATE does not return a cardinality estimate. Instead, it skips the final estimation step and returns the algorithm state itself. The state is a binary of at most 4096 Bytes. For more information, see Estimating the Number of Distinct Values.
- See also:
Syntax¶
Aggregate function
Window function
For details about the OVER clause, see Window function syntax and usage.
Arguments¶
exprThe expression for which you want to estimate cardinality (number of distinct values). This is typically a column name, but can be a more general expression.
Usage notes¶
This function can be used as an aggregate function or a window function.
DISTINCT is supported syntactically, but has no effect.
Examples¶
This shows one step towards estimating the number of distinct postal codes in province(s) of Canada. In this step, we calculate the approximate number of distinct postal codes in Manitoba and store an internal representation of the “state” of the calculation, which we can later combine with similar information for other provinces:
Here is another example. 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: