HLL_COUNT_EXTRACT函数用于从HLL++数据结构(sketch)中计算基数估计值。
注意事项
HLL_COUNT_EXTRACT/HLL_COUNT_MERGE/HLL_COUNT_MERGE_PARTIAL函数使用的BINARY数据需要来源于HLL_COUNT_INIT函数, 不能来源于其他系统或者其他方式。
命令格式
BIGINT HLL_COUNT_EXTRACT(BINARY <sketch>)参数说明
sketch:必填,BINARY类型。HLL++ sketch,由HLL_COUNT_INIT函数生成。
返回值说明
返回BIGINT类型的基数估计值。如果输入sketch为 NULL, 返回0。
使用示例
查询每个国家中至少有一张发票的自然人数量。
SELECT
country,
HLL_COUNT_EXTRACT(HLL_sketch) AS distinct_customers_with_open_invoice
FROM
(
SELECT
country,
HLL_COUNT_INIT(customer_id) AS hll_sketch
FROM values
('UA', 'customer_id_1', 'invoice_id_11'),
('BR', 'customer_id_3', 'invoice_id_31'),
('CZ', 'customer_id_2', 'invoice_id_22'),
('CZ', 'customer_id_2', 'invoice_id_23'),
('BR', 'customer_id_3', 'invoice_id_31'),
('UA', 'customer_id_2', 'invoice_id_24')
t(country, customer_id, invoice_id)
GROUP BY country
);返回结果:
+---------+--------------------------------------+
| country | distinct_customers_with_open_invoice |
+---------+--------------------------------------+
| BR | 1 |
| CZ | 1 |
| UA | 2 |
+---------+--------------------------------------+相关函数
HLL_COUNT_EXTRACT函数属于HyperLogLog++函数,MaxCompute支持一系列近似聚合的HyperLogLog++函数,更多相关函数请参见HyperLogLog++函数。
该文章对您有帮助吗?