设计为相同分区的数据进行数据去重。
特点
- 使用ORDER BY排序键作为唯一键
- 以分区为单位进行去重,只在分区合并时触发
- 如果参数没设置列,则保留重复数据的最后一行
使用
CREATE TABLE replace_table
(
id String,
code String,
time DateTime
) ENGINE = ReplacingMergeTree(time)
PARTITION BY toYYYYMM(time)
ORDER BY (id, code)
PRIMARY KEY id;
INSERT INTO replace_table
VALUES ('001', 'C1', toDateTime('2021-09-21 14:00:00')),
('001', 'C1', toDateTime('2021-09-22 15:00:00')),
('001', 'C1', toDateTime('2021-09-21 19:00:00')),
('001', 'C2', toDateTime('2021-09-22 17:00:00')),
('002', 'C3', toDateTime('2021-09-23 15:00:00'));