1. 程式人生 > >hive增量更新的新方案

hive增量更新的新方案

現在有一種新方案如下:

Select b.id,b.name,b.addr,b.updated_date 
From
(
select a.*,row_number() over(distribute by a.id sort by updated_date) as rn
from
(
        Select id,name,addr, updated_date from test
Union all
Select id,name,addr, updated_date from test_delta 
where y=’2016and m=’10and d=’09’
) a
) b
Where
b.rn = 1

把中間表和最終表進行union all合併,然後取出相同主鍵的那條資料updated_date最新的那條資料。

這種方法和前面left join的方法都很消耗效能,其中left join是合併的時候消耗效能,而union all 是排序的時候消耗效能。總體測試上面來看,union all 略優於 left join