我们可以使用 AggregatedMergeTree 表引擎,它可用于聚合行。
通常在聚合数据中,我们对存储所有唯一标识符不感兴趣,但仍希望进行不同的计数。我们仍然希望能够进行另一次聚合以在之后获得这些行的唯一计数(通过在选择查询中对行进行分组)。
这就是 HyperLogLog 派上用场的地方,它在 clickhouse 中作为 uniqState 函数实现。
我想直接通过插入查询存储 hyperloglog,并将其从我的客户端应用程序提供给 clickhouse 表。这可能吗?
最佳答案
所以我只使用 clickhouse 查询就实现了这一壮举。它的工作非常好!
CREATE TABLE demo_db.aggregates
(
name String,
date Date,
ids AggregateFunction(uniq, UInt8)
) ENGINE = MergeTree(date, date, 8192)
//So here the declaration of a set of ids in the insert query will lead to a binary hash tree being stored
INSERT INTO aggregates SELECT
'Demo',
toDate('2016-12-03'),
uniqState(arrayJoin([1, 5, 6, 7]))
SELECT
name,
date,
uniqMerge(ids) //our hashtree can be grouped and give us unique count over the grouped rows
FROM aggregates
GROUP BY name, date
关于columnstore - 在 clickhouse 中是否可以直接通过插入查询存储 HyperLogLog/uniqState() 状态?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45562213/