【问题标题】:Is it possible in clickhouse to store a HyperLogLog / uniqState() state directly trough an insert query?是否可以在 clickhouse 中通过插入查询直接存储 HyperLogLog / uniqState() 状态?
【发布时间】:2023-04-05 11:03:02
【问题描述】:

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

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

我想通过插入查询直接存储一个超级日志,并从我的客户端应用程序将其提供给 clickhouse 表。这可能吗?

【问题讨论】:

    标签: columnstore clickhouse hyperloglog


    【解决方案1】:

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

    【讨论】:

    • 除此之外,请注意 AggregatingMergeTree 表引擎,它非常有能力建立 uniq 状态并添加到此。 AggregatingMergeTree 似乎是我们想要聚合单独插入的大多数用例的最佳候选者。
    猜你喜欢
    • 1970-01-01
    • 2013-06-18
    • 2019-03-25
    • 2019-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-20
    相关资源
    最近更新 更多