HLL_COMBINE_SKETCHES function - Amazon Redshift

HLL_COMBINE_SKETCHES function

The HLL_COMBINE_SKETCHES is a scalar function that takes as input two HLLSKETCH values and combines them into a single HLLSKETCH.

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.

Syntax

HLL_COMBINE_SKETCHES (hllsketch_expression1, hllsketch_expression2)

Argument

hllsketch_expression1 and hllsketch_expression2

Any valid expression that evaluates to an HLLSKETCH type, such as a column name.

Return type

The HLL_COMBINE_SKETCHES function returns an HLLSKETCH type.

Examples

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

WITH tbl1(x, y) AS (SELECT Hll_create_sketch(1), Hll_create_sketch(2) UNION ALL SELECT Hll_create_sketch(3), Hll_create_sketch(4) UNION ALL SELECT Hll_create_sketch(5), Hll_create_sketch(6) UNION ALL SELECT Hll_create_sketch(7), Hll_create_sketch(8)), tbl2(x, y) AS (SELECT Hll_create_sketch(9), Hll_create_sketch(10) UNION ALL SELECT Hll_create_sketch(11), Hll_create_sketch(12) UNION ALL SELECT Hll_create_sketch(13), Hll_create_sketch(14) UNION ALL SELECT Hll_create_sketch(15), Hll_create_sketch(16) UNION ALL SELECT Hll_create_sketch(NULL), Hll_create_sketch(NULL)), tbl3(x, y) AS (SELECT * FROM tbl1 UNION ALL SELECT * FROM tbl2) SELECT Hll_combine_sketches(x, y) FROM tbl3;