數據有很多種下發方式:
簡單的來說分為增量和全量。
全量獲取:
當表是一個全量分區表:
一般數據下發的來源表是一個分區表,全量就是一次下發一個分區。
當表是一個增量分區表:
一次性下發全表
當表是一個拉鏈表:
獲取每個客戶的最新狀態全量下發。(偽代碼如下)
select 字段 ( select 字段 ,over (partition by id order by batch_date1 desc) as cnn from table_Z where batch_date ='xxxxxxxx' ) a where cnn =1;
增量獲取:
但是往往非大數據系統無法一口氣吃掉千萬級別的數據量。
一般會采取增量下發的方式。
當表是一個增量分區表:
只需要下發一個分區
當表是一個全量分區表:
需要對今天的分區數據和昨天分區數據的數據進行比對,然后尋找新增,差異,和刪除三部分。然后下發

偽代碼:
新增和差異: 需要約定好增改標識
select 字段,增改標識 (select 字段 from table_F where batch_date=今天) t0 left join (select 字段 from table_F where batch_date=昨天) t1 on t0.id=t1.id where (t0.字段1<>nvl(t1.字段1,'not exist') or t0.字段2<>nvl(t1.字段2,'not exist').....);
刪除:需要約定好 刪除標識
select 字段 ,刪除標識 from (select 字段 from table_F where bacth_date ='昨天') t0 left join (select 字段 from table_F where bacth_date ='今天') t1 on t0.id =t1.id where t1 is null;
不過也可以用outer 的方式實現:
當表是一個全量拉鏈表:
select 字段 from table_Z where batch_date='今天' and stat_date='今天'
