1.为什么要做hive拉链表
1.表数据量比较大,每天都保存全量占用空间过多。
2.每天更新、新增、删除的数据量比较小。
3.为了减少存储空间,将表做拉链处理。
以下方案未考虑到拉链效率问题,及查询拉链表效率问题。接下来说一下第一种情况(增量数据与删除数据在不同的表中,其中id为主键)的拉链实现方式:
2.涉及到的表
日增量表 table_t
create table if not exists table_t (
id string,
product string,
price string)
partitioned by (day string);
日删除表table_d
create table if not exists table_d (
id string,
product string,
price string)
partitioned by (day string);
临时表 table_1
create table if not exists table_1(
id string,
product string,
price string,
start_day string,
end_day string);
结果表table
create table if not exists table(
id string,
product string,
price string,
start_day string
end_day string);
3.处理日增量及日删除数据
3.1处理每天的增量数据
将每天的增量数