HLL_COMBINE function - Amazon Redshift
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

HLL_COMBINE function

The HLL_COMBINE aggregate function returns an HLLSKETCH data type that combines all input HLLSKETCH values.

The combination of two or more HyperLogLog sketches is a new HLLSKETCH that encapsulates information about the union of the distinct values that each input sketch represents. After combining sketches, Amazon Redshift extracts the cardinality of the union of two or more datasets. For more information on how to combine multiple sketches, see Example: Return a HyperLogLog sketch from combining multiple sketches.

Syntax

HLL_COMBINE (hllsketch_expression)

Argument

hllsketch_expression

Any valid expression that evaluates to an HLLSKETCH type, such as a column name. The input value is the HLLSKETCH data type.

Return type

The HLL_COMBINE function returns an HLLSKETCH type.

Examples

The following example returns the combined HLLSKETCH values in the table hll_table.

CREATE TABLE a_table(an_int INT, b_int INT); INSERT INTO a_table VALUES (1,1), (2,1), (3,1), (4,1), (1,2), (2,2), (3,2), (4,2), (5,2), (6,2); CREATE TABLE hll_table (sketch HLLSKETCH); INSERT INTO hll_table select hll_create_sketch(an_int) from a_table group by b_int; SELECT hll_combine(sketch) AS sketches FROM hll_table; sketches ---------------------------------------------------------------------------------------------------------------------------- {"version":1,"logm":15,"sparse":{"indices":[20812342,20850007,22362299,40314817,42650774,47158030],"values":[1,2,1,3,2,1]}} (1 row)