DATASKETCHES_HLL
functionsupportedCore SQL functionsReturns an approximation of the distinct cardinality of the input (that is, DATASKETCHES_HLL(col1) returns an approximation of COUNT(DISTINCT col1)). 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.
Syntax
supportedpartialnot supportednot scored
Aggregate function
DATASKETCHES_HLL( [ DISTINCT ] <expr1> [ , <max_log_k> ] )
Window function
DATASKETCHES_HLL( [ DISTINCT ] <expr1> [ , <max_log_k> ] )
OVER ( [ PARTITION BY <expr2> ] )
Parameters
| Name | Required | Description |
|---|---|---|
expr1 | required | The expression for which you want to know the number of distinct values. |
max_log_k | optional | The maximum value, in log2, of K to initialize the datasketches HLL object. Specify an INTEGER value between 4 and 21, inclusive. For more information, see the Apache DataSketches documentation. Default: 12 |
expr2 | optional | The optional expression used to group rows into partitions. |
Returns
The function returns a value of type DOUBLE. If the input is empty, the output is 0.0.
Usage notes
- DISTINCT is supported syntactically, but has no effect.
- The function supports arguments that are values of the following data types: String & binary data types (for example, VARCHAR and BINARY). For example, the following function calls are supported: Copy code SELECT DATASKETCHES_HLL_ACCUMULATE(1::TEXT); Copy code SELECT DATASKETCHES_HLL_ACCUMULATE(TO_BINARY(HEX_ENCODE(1), 'HEX'));
- Data types for floating-point numbers (for example, FLOAT and DOUBLE) The DataSketches library casts these values to DOUBLE values.
- Data types for fixed-point numbers (for example, INTEGER and NUMERIC). The function only supports numeric types with a scale of 0. However, you can cast numeric values with a scale other than 0 to a data types for a floating-point number. The DataSketches library casts these values in the range of a 64-bit signed INTEGER to a 64-bit signed INTEGER value. The DataSketches library doesn’t directly cast INTEGER values exceeding the 64-bit signed INTEGER range (such as 128-bit integer values). However, Snowflake still supports these values by automatically converting them to DOUBLE values, which DataSketches supports. This behavior is identical to the behavior of the datasketches-python library.
- Values of other data types aren’t supported. For example, VARIANT and ARRAY values aren’t supported.
- For information about NULL values and aggregate functions, see Aggregate functions and NULL values.
- When this function is called as a window function, it doesn’t support: An ORDER BY clause within the OVER clause.
- Explicit window frames.