|
拉链算法总结大全: 一、0610算法(追加) 1、删除仓库表的加载日期是本次加载日期的数据,以支持重跑 delete from xxx where start_dt >=$tx_date; 2、创建临时表,用于存放从源表中提取的数据 create multiset volatile table xxx; 3、向临时表中插入数据,按照一定规则加工 insert into xxx select ... from xxx; 4、对于临时表的数据打上时间戳直接插入仓库表中 insert into xxx select ... from xxx; 二、0611算法(全删全插) 1、将仓库表中主键处于源表的字段记录删除 delete from xxx where (id) in (select id from xxx); 2、将源表的所有数据直接插入到仓库表中 insert into xxx select ... from xxx; 三、0612算法(历史拉链算法) 1、删除仓库表的加载日期是本次加载日期的数据,用于支持重跑 delete from xxx where start_dt >= $tx_date; 2、修改仓库表的结束日期字段,作用是把结束日期大于加载日期并且不是最大日期的数据的结束日期置为最大日期,使其有效 update set end_dt=$max_dt where end_dt >= $tx_date and end_dt <> max_dt; 3、创建临时表用于存放从源表中提取的数据 create multiset volatile table new; 4、创建临时增量表用于存放增量数据 create multiset volatile table inc; 5、根据一定的规则向临时表中加载源表数据,根据需求而定 insert into new select ... from xxx where ...; 6、用临时表的数据与仓库表数据作对比,将新增和更改的数据存入增量表中 insert into inc select ... from new where .. not in ..; 7、对所有在增量表的并且是有效的数据进行关链处理 update xxx set end_dt=$tx_date where ...; 8、对所有处于增量表中的数据进行拉新链处理 insert into xxx select ... from inc;
|