HIVE腳本優化

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)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章