Clickhouse uniqExact 聚合函数无法正常工作
Clickhouse uniqExact Aggregate function not work correctly
我有table这个模式
event_time DateTime,
field1 String,
field2 String,
field3 String
我想用 SummingMergeTree
引擎创建新的 table(table
) 来聚合一些在线查询的数据。为此,我像这样创建 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);
之后我将数据插入到新的 table:
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;
现在,当我查询查找 field3
的 uniqExact
时:
select uniqExact(uniq_field3_state) from aggregated_table;
我的回答是:
┌─uniqExact(uniq_field3_state)─┐
│ 356948 │
└──────────────────────────────┘
但是当我查询来源时 table 我的回答是:
┌─uniqExact(field3)─┐
│ 15548 │
└───────────────────┘
这个工作流程有什么问题吗?
您必须通过 -Merge 或 -Finalize 函数来完成 STATE 计算。
在您的示例中,您必须使用 uniqExactMerge
而不是 uniqExact。
select uniqExactMerge(uniq_field3_state)
from aggregated_table;
我有table这个模式
event_time DateTime,
field1 String,
field2 String,
field3 String
我想用 SummingMergeTree
引擎创建新的 table(table
) 来聚合一些在线查询的数据。为此,我像这样创建 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);
之后我将数据插入到新的 table:
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;
现在,当我查询查找 field3
的 uniqExact
时:
select uniqExact(uniq_field3_state) from aggregated_table;
我的回答是:
┌─uniqExact(uniq_field3_state)─┐
│ 356948 │
└──────────────────────────────┘
但是当我查询来源时 table 我的回答是:
┌─uniqExact(field3)─┐
│ 15548 │
└───────────────────┘
这个工作流程有什么问题吗?
您必须通过 -Merge 或 -Finalize 函数来完成 STATE 计算。
在您的示例中,您必须使用 uniqExactMerge
而不是 uniqExact。
select uniqExactMerge(uniq_field3_state)
from aggregated_table;