clickhouse - Clickhouse uniqExact 聚合函数无法正常工作
问题描述
我有这个模式的表
event_time DateTime,
field1 String,
field2 String,
field3 String
我想table
用引擎创建新表()SummingMergeTree
来聚合一些在线查询的数据。为此,我创建了这样的表:
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;
现在,当我查询查找uniqExact
时field3
:
select uniqExact(uniq_field3_state) from aggregated_table;
我的回答是:
┌─uniqExact(uniq_field3_state)─┐
│ 356948 │
└──────────────────────────────┘
但是当我查询源表时,我的答案是:
┌─uniqExact(field3)─┐
│ 15548 │
└───────────────────┘
这个工作流程有什么问题吗?
解决方案
您必须通过 -Merge 或 -Finalize 函数完成状态计算。
在您的示例中,您必须使用uniqExactMerge
not uniqExact。
select uniqExactMerge(uniq_field3_state)
from aggregated_table;
推荐阅读
- powershell - Itext7 HTML2PDF - 图片未在 PDF 文件中旋转
- jquery - Hubspot 表单:运行 onFormReady 函数时出错
- c# - 在 ASP.NET Core 中使用 SQL 视图的数据访问如何更好地构建模型?
- pandas - 我想对数据透视表进行多级排序
- azure-data-factory - Azure 数据工厂查找活动在读取有空格的列名时出现问题
- javascript - 为什么会出现错误:React.Children.only 期望接收单个 React 元素子元素。?
- spring-boot - Spring boot 2.4 - 必须在构建器或设置环境中提供显式区域以提供区域
- pandas - 熊猫分析相关警告似乎是错误的
- php - 路由登录未定义,如果管理员用户当前未登录,我在尝试将页面重定向到登录时不断收到此错误
- c - 装配中的缓冲器