如何解决Clickhouse uniqExact Aggregate函数无法正常运行
我有带有此架构的表
event_time DateTime,field1 String,field2 String,field3 String
我想用table
引擎创建新表(SummingMergeTree
)来汇总一些在线查询的数据。为此,我创建这样的表:
CREATE TABLE aggregated_table(
event_day DateTime,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,field2,count(*) AS request_num,uniqExactState(field3) As uniq_field3_state
FROM table
GROUP BY event_day,field2;
现在,当我查询以找到uniqExact
中的field3
时:
select uniqExact(uniq_field3_state) from aggregated_table;
我的答案是:
┌─uniqExact(uniq_field3_state)─┐
│ 356948 │
└──────────────────────────────┘
但是当我查询源表时,我的答案是:
┌─uniqExact(field3)─┐
│ 15548 │
└───────────────────┘
此工作流程是否有问题?
解决方法
您必须通过-Merge或-Finalize函数完成STATE的计算。
在您的示例中,您必须使用uniqExactMerge
而不是uniqExact。
select uniqExactMerge(uniq_field3_state)
from aggregated_table;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。