ETL拉链算法

编程入门 行业动态 更新时间:2024-10-10 11:25:11

ETL<a href=https://www.elefans.com/category/jswz/34/1763390.html style=拉链算法"/>

ETL拉链算法

0610算法:(通常用于流水事件表)

逻辑最简单的算法之一

将目标表的数据删除掉加载日期是本次加载日期的数据,支持重跑:

delete from xxx where calc_dt=$tx_date;

创建临时表用于存储临时数据:

create  multiset volatile table new;

或者清空之前创建的new表

truncate table new;

向new表中添加本次数据:

insert into new select [来源excel] from xxx;

向目标表中插入数据:

insert into xxx select * from new;

0611算法:(merge into算法)

首先创建两个临时表或将两个表清空

create multiset volatile table new /inc

turncate table new /inc

将新数据加载到new表中

insert into new select * from xxx 来源excel

将与目标表不一样的数据放入inc表中:

select insert into inc select * from new where (所有字段) not in (select  * from  xxx )

将inc中的数据更新到目标表中:

merge into xxx O using inc N on(O.EVI_ID=N.EVI_ID) 

when matched then 

upset set 所有字段=N.所有字段

when not matched then 

insert (N.所有字段)

0612算法:(常规拉链算法)

首先得到两个表,和上面一样。

然后将新的数据插入值new表中:

insert into new select * from xxx 来源excel

然后将new表中和目标表不一样的数据加载到inc中:

insert into inc select * from new where (所有字段) not in (select * from xxx)

将目标表中相应的数据修改日期:

update xxx set end_date=date '$tx_date'   where date=date'$max_date'

最后一步将数据添加至目标表中:

insert into xxx select *(但是这里的end_date='$max_Date') from inc

0613算法:(经济型拉链算法)

和0612算法的基础上最后一步加一个条件:

where 所有字段<>'',and end_date<>date"$min_date'

0614算法:(带删除的历史拉链算法)

获取两个临时表。

首先修改目标表

update xxx set end_date='$max_date' where end_date>date'$tx_date' and end_date<>'max_Date'

将数据插入new

insert into new select * from xxx来源excel

new中与目标表中不一样的数据加载到inc

insert into inc select * from new where (所有字段 ) not in (Select  * from xxx)

将在目标表中的数据,且不在new中的本次数据加载到inc中

insert into inc select *(date ='$ min_date') from xxx where (项目号,日期)not in(date='$max_date),and 项目号=xxx)and (xxx) not in (select * from new) ;

将目标表中的end_date进行修改

update xxx set end_date='$tx_date' where end_date=date'$max_date' and (acctiong_main_book_cd,acct_subj_num) in ( select 主键 from inc)

最后将数据插入到目标表中 

insert into xxx select * from inc where end_dt<>'$ min_Date'

0617算法:(经济型历史拉链算法)

在0614的基础上最后一句添加idtfy_content_effect <>'${null_date}'

0618算法:(PK NOT_IN_APPEND算法)

最简单的算法之一:

首先将上次重新弄错的数据进行删除:

delete from xxx where etl_tx_dt>=$tx_date

获取一个临时表

将新的数据插入new中

insert Into new select * 来源于excel from xxx where一些条件,

将new中的数据插入到目标表中:

insert into xxx select * from new where  (主键) not in (select 主键 from xxx)

0619算法:以源日期字段自拉链数据

获取两个临时表

向new表中加载数据:

insert into new select * from xxx 来源excel

将旧数据加载到new中

insert into new select * from xxx where etl_job_num=xxx and (主键 ) not in (select 主键 from xxx)

在new中使用日期进行自拉链的方式将数据插入至inc中:

insert into inc with  T (*,N) as (select *,row() over (partition  by 主键 order by start_dt) from new ) select 所有字段 from T T1 left join T T2 on T1.主键=T2.主键 and T1.N=T2.N-1  where (所有字段)   not in (select 所有字段 from xxx)

最后一步更新目标表

merge into xxx A using inc B on A.主键=B.主键 and A.start_dt=B.start_dt

when matched then 

update set 除了主键、start_dt、etl_tx_dt=B.相应字段

我很 not matched then

insert (B.所有字段)

0620算法:(清空目标表的APPEND算法)

清空临时表:

truncate table new

insert in to new select * from xxx 来源excel

delete from xxx

insert into xxx select * from new

更多推荐

ETL拉链算法

本文发布于:2024-02-14 11:02:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1762970.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:拉链   算法   ETL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!