HLL_COMBINE_SKETCHES 函数 - Amazon Redshift

HLL_COMBINE_SKETCHES 函数

HLL_COMBINE_SKETCHES 是一个标量函数,它将两个 HLLSKETCH 值作为输入,并将它们合并为单个 HLLSKETCH 值。

两个或多个 HyperLogLog 草图的组合是一个新的 HLLSKETCH,它封装了有关每个输入草图所表示的不同值的并集的信息。

语法

HLL_COMBINE_SKETCHES (hllsketch_expression1, hllsketch_expression2)

参数

hllsketch_expression1hllsketch_expression2

计算结果为 HLLSKETCH 类型的任何有效表达式(如列名称)。

返回类型

HLL_COMBINE_SKETCHES 函数返回一个 HLLSKETCH 类型。

示例

以下示例返回表 hll_table 中的合并 HLLSKETCH 值。

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;