ETL拉链算法汇总大全

拉链算法总结大全:
一、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;
四、0614(带删除的历史拉链算法)
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、创建暂时增量表用于存放增量数据,这里会存放源系统物理删除的数据并使用min_date进行标识
create multiset volatile table inc;
5、依据一定的规则向暂时表中载入源表数据,依据需求而定
insert into new select ... from  xxx where ...;
6、用暂时表的数据与仓库表数据作对照。将新增和更改的数据存入增量表中
insert into inc select ... from new where .. not in ..;
7、用仓库表的有效数据主键跟暂时表数据主键作对照 in 仓库表 not in 暂时表的即为源系统物理删除的字段。将其end_dt用min_date标识存入增量表(这条数据来源于仓库)
insert into .. select ... from where end_dt=$max_date and etl_job_num=920 and (agt_num,agt_modif_num) not in (select agt_num,agt_modif_num from new)
8、对全部在增量表的而且是有效的数据进行关链处理
update xxx set end_dt=$tx_date where ...;
9、对全部处于增量表中的而且end_dt标识不是min_date的数据进行拉新链处理
insert into xxx select ... from inc where end_dt <> $min_date;
五、0616(经济型历史拉链算法)
1、设置事无级别为RU优先于其它事务
set session characteristics as transaction isolation level ru
2、创建暂时表用于存放从源表中提取的数据
create multiset volatile table new
3、创建增量表用于存放增量数据 这里仅仅会存放新增个更改的数据
create multiset volatile table inc
4、创建删除表用于存放逻辑删除数据 带有特殊标识的逻辑删除数据
create multiset volatile table del
5、向暂时表中插入数据依照一定的载入规则
insert into new 
6、用暂时表的数据与仓库表数据作对照将新增的更改的数据存入增量表中
insert into inc select ... from new 
7、将源表数据中有特殊标识的(一般为end_dt=min_date)存入删除表中
insert into del select .. from new where end_dt=min_date
8、对全部在增量表和删除表中数据进行关链处理
update xxx set end_dt=$tx_date where ...
9、对全部在增量表中的数据拉新链除了指定项
insert into xxx select ... from inc where seq_num <>''
六、0613(逻辑删除的历史拉链算法)
0613和0616差点儿一样,除了最后一步
9、对全部在增量表中的数据拉新链

原文地址:https://www.cnblogs.com/lytwajue/p/7222294.html