【问题标题】:Clickhouse uniqExact Aggregate function not work correctlyClickhouse uniqExact 聚合函数无法正常工作
【发布时间】:2021-01-25 06:10:56
【问题描述】:

我有这个架构的表

event_time DateTime,
field1 String,
field2 String,
field3 String

我想用SummingMergeTree 引擎创建新表(table) 来聚合一些在线查询的数据。为此,我创建了这样的表:

CREATE TABLE aggregated_table(
  event_day DateTime,
  field1 String,
  field2 String,
  record_num UInt64,
  uniq_field3_state AggregateFunction(uniqExact, String)
)
ENGINE = SummingMergeTree()
ORDER BY (event_day, field1, field2);

之后我将数据插入新表:

INSERT INTO aggregated_table
SELECT
  toStartOfDay(event_time) as event_day,
  field1,
  field2,
  count(*) AS request_num,
  uniqExactState(field3) As uniq_field3_state
FROM table
GROUP BY event_day, field1, field2;

现在,当我查询以查找 uniqExactuniqExact 时:

select uniqExact(uniq_field3_state) from aggregated_table;

我的答案是:

┌─uniqExact(uniq_field3_state)─┐
│                       356948 │
└──────────────────────────────┘

但是当我查询源表时,我的答案是:

┌─uniqExact(field3)─┐
│             15548 │
└───────────────────┘

这个工作流程有什么问题吗?

【问题讨论】:

    标签: clickhouse


    【解决方案1】:

    您必须通过 -Merge 或 -Finalize 函数完成状态计算。

    在您的示例中,您必须使用 uniqExactMerge 而不是 uniqExact。

    select uniqExactMerge(uniq_field3_state) 
    from aggregated_table;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-01
      • 1970-01-01
      • 2018-09-01
      • 2019-09-14
      • 2014-06-08
      • 2015-07-19
      • 2014-04-04
      相关资源
      最近更新 更多