Categories:

Aggregate Functions (Cardinality Estimation) , Window Functions

HLL

Uses HyperLogLog to return an approximation of the distinct cardinality of the input (i.e. HLL(col1, col2, ... ) returns an approximation of COUNT(DISTINCT col1, col2, ... )).

For more information about HyperLogLog, see Estimating Number of Distinct Values.

Aliases:

APPROX_COUNT_DISTINCT

See also:

HLL_ACCUMULATE , HLL_COMBINE , HLL_ESTIMATE

Syntax

HLL( [ DISTINCT ] <expr> [ , ... ] )

HLL(*)

Usage Notes

Examples

SELECT COUNT(DISTINCT o_orderdate), HLL(o_orderdate) FROM orders;

-----------------------------+------------------+
 COUNT(DISTINCT O_ORDERDATE) | HLL(O_ORDERDATE) |
-----------------------------+------------------+
 2406                        | 2398             |
-----------------------------+------------------+
SELECT o_orderstatus, HLL(o_orderdate, o_custkey) FROM orders GROUP BY 1 ORDER BY 2;

---------------+-----------------------------+
 O_ORDERSTATUS | HLL(O_ORDERDATE, O_CUSTKEY) |
---------------+-----------------------------+
 P             | 729                         |
 O             | 14444                       |
 F             | 14859                       |
---------------+-----------------------------+