概念
Duplicate Key模型,导入数据时不会产生聚合,源数据不失真。
被指定为Duplicate Key的字段用来指示底层数据按照该字段排序。
如:对于日志分析,不在意多几条,少几条数据,只关心排序,这时候Duplicate Key模型就有用武之地了。
create table if not exists test_db.example_log
(
`log_time` datetime not null comment "日志时间",
`type` int not null comment "日志类型",
`error_code` int comment "错误码",
`error_msg` varchar(1024) comment "错误详细信息",
`op_id` bigint comment "负责人id",
`op_time` datetime comment "处理时间"
)
duplicate key (`log_time`, `type`)
distributed by hash(`log_time`) buckets 10;
特点
- 适用于数据即没有主键,也没有聚合需求的场景
- 虽然不能使用预聚合功能,但是,可以发挥列存储模型的优势,只读取相关列,不需要读取所有字段的列。