APACHE_DATASKETCHES_HLL_MERGE

An aggregate function. Merges one or more Apache DataSketches HLL sketches that were built using the aggregate function APACHE_DATASKETCHES_HLL_BUILD into a new sketch.

In order to get correct results each sketch must be built on the same <expression> datatype. Attempts to merge sketches for different datatypes will NOT result in an error, and it’s the user responsibility to merge skeches with the same datatype only. For example, you can merge a sketch built from INTEGER data with one built from TEXT data but the estimated cardinality will be incorrect.

If sketches are with different hll precision and hll type the merged sketch will be built with lowest precision and type of all inputs. For example, you can merge a sketch built with precision 13 and a sketch built with precision 14 and the result precision will be 13.

Syntax

APACHE_DATASKETCHES_HLL_MERGE
(<expression>)

Parameters

Parameter Description Supported input types
<expression> An Apache DataSketches HLL sketches in a valid format, e.g. the output of the APACHE_DATASKETCHES_HLL_BUILD function. BYTEA

Return Type

BYTEA

Error Handling

If the input expression is not a valid Apache DataSketches HLL sketches, the function will raise an error. Ensure that the input is correctly formatted and generated by the APACHE_DATASKETCHES_HLL_BUILD function.

Example

Following the example in APACHE_DATASKETCHES_HLL_BUILD:

SELECT APACHE_DATASKETCHES_HLL_ESTIMATE(APACHE_DATASKETCHES_HLL_MERGE(a)) AS estimate,
       APACHE_DATASKETCHES_HLL_MERGE(a)                                   AS merged_sketch
FROM sketch_of_data_to_count;
estimate BIGINT merged_sketch BYTEA
6673219 \x0a0107120018000a….