通常在hive中進行資料處理,處理好的資料再推送到oracle中使用,需要保持兩邊資料一緻,再推送的時候最好的方式是sqoop的merge形式全量推送,但這樣消耗的資源、時間很長,可以隻推送新增、更新、删除的資料給oracle,之後再再oracle中對目标表再單獨的執行一段merge程式進行更新,篩選出這些資料的sql可參考下面這樣的示例:
其中:from 使用多模式插入
tel_m存儲 新增、更新的資料
tel_d存儲需要删除的資料、無效資料
from( select pre.tel_num as pre_tel_num,
pre.shield_code as pre_shield_code,
pre.shield_reason as pre_shield_reason,
new.tel_num,
new.shield_code,
new.shield_reason
from (select tel_num,
shield_code,
shield_reason,
pa_tcims_concat(tel_num,shield_code,shield_reason) as all_columns
from database_name.view_risk_tel where op_new = '${pre_new}') pre
full outer join (select tel_num,
shield_code,
shield_reason,
pa_tcims_concat(tel_num,shield_code,shield_reason) as all_columns
from database_name.view_risk_tel where op_new = '${nominal_formate_date}') new
on pre.all_columns = new.all_columns
) ainsert overwrite table database_name.tel_m partition(op_new='${nominal_formate_date}')
select a.tel_num,
a.shield_code,
a.shield_reason
where a.pre_tel_num is null
insert overwrite table database_name.tel_d partition(op_new='${nominal_formate_date}')
select a.pre_tel_num as tcims_cust_id,
a.pre_shield_code as shield_code,
a.pre_shield_reason as shield_reason
where a.tel_num is null;
--去掉D表中 在M表中存在的資料
insert overwrite table database_name.tel_d partition
(op_new = '${nominal_formate_date}')
select d.tel_num, d.shield_code, d.shield_reason
from (select a.tel_num, a.shield_code, a.shield_reason
from database_name.tel_d a
where op_new = '${nominal_formate_date}') d
left outer join (select b.tel_num, b.shield_code, b.shield_reason
from database_name.tel_m b
where op_new = '${nominal_formate_date}') m on d.tel_num =
m.tel_num
where m.tel_num is null;
之後将這兩個表推送到oracle,再單獨對roacle的tel表執行一段merge程式即可使兩邊保持一緻,避免了全量推送;節省了資源;