尝试了解如何使 mv_test_data_mv MV 每 1 分钟刷新一次。没有找到任何有关 SummingMergeTree 表的示例:( 有什么想法吗? 这是具有常用物化视图的表的示例。
CREATE TABLE guardicore.mv_test_data_tmp
(
`id` UUID,
`some_id` UUID,
`count` UInt32,
`aggr_id` FixedString(64),
`start_time` DateTime64(6)
)
ENGINE = MergeTree
PARTITION BY toDate(start_time)
ORDER BY start_time
TTL toDateTime(start_time) + toIntervalHour(1);
CREATE TABLE guardicore.mv_test_data
(
`id` UUID,
`some_id` UUID,
`count` Nullable(UInt32),
`aggr_id` FixedString(64),
`start_15m` DateTime
)
ENGINE = SummingMergeTree
PARTITION BY toDate(start_15m)
ORDER BY (aggr_id, start_15m);
CREATE MATERIALIZED VIEW guardicore.mv_test_data_mv TO guardicore.mv_test_data
(
`aggr_id` FixedString(64),
`start_time` DateTime,
`count` Nullable(UInt64),
`some_id` UUID,
`id` UUID,
) AS
SELECT
aggr_id,
anyLast(id) AS id,
anyLast(some_id) AS some_id,
toStartOfFifteenMinutes(start_time) AS start_15m,
sum(count) AS count,
FROM guardicore.mv_test_data_tmp
GROUP BY
aggr_id,
start_15m
ORDER BY
aggr_id,
start_15m
ClickHouse 中的 MV 在数据插入底层源表时更新。它们不支持基于时间间隔的刷新操作。
如果您需要每分钟刷新一次 MV,您可以使用 ClickHouse 外部的计划任务定期将新日期插入源表 Guardicore.mv_test_data_tmp。这将触发 MV 更新。