1.写HIVE脚本时,要善于使用multi-insert语法
insert into(或者overwrite) table1 partition(dt = ‘2017-11-02’)
select a, b
from app.app_m04_order_info //增量表
where dt >= sysdate(-2) ;
insert into(或者overwrite) table2 partition(dt = ‘2017-11-02’)
select a, b
from app.app_m04_order_info //增量表
where dt >= sysdate(-2) ;
Hive会进行解析,分成两个job 分别执行,因为使用两个语句。
优化方案:
使用multi-insert语句,实现一次读写,写入两个表中
from app.app_m04_order_info
insert into(或者overwrite) table1 partition(dt = ‘2017-11-02’)
select a,b
where dt >= sysdate(-2)
insert into(或者overwrite) table2 partition (dt = ‘2017-11-03’)
select c
where dt >= sysdate(-1)
2. union all语句,不同表的union all 会多次读写,同一张表的union all,只需要读取数据一次Map,实现不同条件过滤数据,推送到不同的地方。
select a,b
from app.app_m04_order_info1
where dt >= sysdate(-2)
union all
select a,b
from app.app_m04_order_info2
where dt >= sysdate(-2)
select a,b
from app.app_m04_order_info1
where dt >= sysdate(-2)
union all
select a,b
from app.app_m04_order_info1
where dt >= sysdate(-3)