在 Clickhouse 中是否可以通过插入查询直接存储 HyperLogLog / uniqState() 状态?

Is it possible in clickhouse to store a HyperLogLog / uniqState() state directly trough an insert query?

我们可以使用 AggregatedMergeTree table 引擎,它可用于聚合行。

通常在聚合数据中,我们对存储所有唯一标识符不感兴趣,并且仍然希望进行不同的计数。我们仍然希望能够进行另一次聚合以在之后获得这些行的唯一计数(通过 select 查询中的分组行)。 这就是 HyperLogLog 派上用场的地方,它在 clickhouse 中作为 uniqState 函数实现。

我想通过插入查询直接存储 hyperloglog,并从我的客户端应用程序将其提供给 clickhouse table。这可能吗?

所以我仅使用 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