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)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值