Skip to main content
An aggregate function that creates a new HyperLogLog sketch. This sketch is compatible only with the HyperLogLog sketch of the Apache DataSketches library. HyperLogLog (HLL) sketches are a highly efficient probabilistic data structure used for cardinality estimation. The APACHE_DATASKETCHES_HLL_BUILD function is used to create a new HLL (HyperLogLog) sketch from a dataset. This is particularly useful for large datasets where exact counting is computationally expensive. Multiple sketches can be merged to a single sketch using the aggregate function APACHE_DATASKETCHES_HLL_MERGE. To estimate the final distinct count value from a sketch, the scalar function APACHE_DATASKETCHES_HLL_ESTIMATE can be used. APACHE_DATASKETCHES_HLL_BUILD requires less memory than exact count distinct aggregation, but also introduces statistical error. For more information see Apache HyperLogLog sketch docs.

Syntax

Parameters

Return Type

BYTEA

Performance Considerations

Using HLL sketches is efficient for large datasets, but the accuracy of the estimate can vary. It is recommended to understand the trade-offs between accuracy and performance when using this function. For more information, see Apache DataSketches HLL Performance.

Compatibility With Other Systems

The created sketch is compatible with all the other systems that support the HyperLogLog sketch of the Apache DataSketches library. Few systems applies different encoding before inserting data to the sketch and after creating the sketch, so the sketches created by this function may be incompatible with them as is, but with encoding modification it should be compatible.

UTF-16 Little Endian Text Encoding

Few vendors (Imply/Druid) use UTF-16 Little Endian encoding for text data before inserting it into the sketch. In order to be compatible with them, we added this optional parameter. This transition to UTF-16 little endian encoding is done before hashing (sending the string to the DataSketches lib). For example the string ‘ab’ in UTF-8 encoded as ‘0x3132’. in UTF-16: ‘0x00310032’. in UTF-16LE: ‘0x31003200’.

Sketch Blob Encoding

Few vendors (Imply/Druid) apply different encoding to the sketch blob after creating the sketch. In the Druid Database they apply base64 encoding to the sketch blob, in order to make this function sketch compatible with theirs, you can use the following queries: In order to export a sketch that is compatible with Druid, you can use the following query:
In order to import a sketch that is created with Druid, you can use the following query:

Example