【发布时间】:2020-04-11 08:38:25
【问题描述】:
我已经创建了一个表:
CREATE TABLE results
(
id UUID,
date_time DateTime,
item_id UInt32,
value UInt16
) ENGINE = MergeTree()
PARTITION BY toYYYYMMDD(date_time)
ORDER BY (date_time, item_id);
我想创建一个物化视图来存储每小时直方图数据的价值。例如;
我希望得到这样的输出:
toStartOfHour item_id value count
2019-12-18 00:00:00 1 0 4 /* number of rows with value between 0 and 100 and date_time between 2019-12-18 00:00:00 and 2019-12-18 01:00:00 */
2019-12-18 00:00:00 1 100 7 /* number of rows with value between 100 and 200 and date_time between 2019-12-18 00:00:00 and 2019-12-18 01:00:00 */
value 介于 100 和 0 之间,date_time 介于 2019-12-18 00:00:00 和 2019-12-18 01:00:00 之间的行数。我尝试过这样的事情:
CREATE MATERIALIZED VIEW results_histogram_by_hour
ENGINE = AggregatingMergeTree()
PARTITION BY toYYYYMMDD(date_time)
ORDER BY (date_time, item_id)
POPULATE
AS SELECT toStartOfHour(date_time) AS date_time,
item_id,
multiply(floor(value / 100), 100) AS value,
countState() AS count
FROM results
GROUP BY date_time,
item_id,
value;
此物化视图定义在填充时有效。但是随着时间的推移和新的行,它会出错。怎么错了?我不知道。我找不到模式。
我不确定我是否在 clickhouse 上发现了错误,或者我做错了什么。
我的物化视图定义正确吗?
【问题讨论】:
-
github.com/ClickHouse/ClickHouse/issues/8278 应该是 ORDER BY (date_time, item_id, value)
标签: sql clickhouse