Pig 和 Hive 的表连接 Join

Pig:

1.  内连接:

 join_table = join table1 by col1,  join table2 by col2


2. 外连接:

左外连接:join_table = join table1 by col1 left  outer,  join table2 by col2     其中outer 可省略

右外连接:join_table = join table1 by col1 right  outer,  join table2 by col2   其中outer 可省略

全外连接:join_table = join table1 by col1 full  outer,  join table2 by col2


3. 自连接
不能直接进行: join table1 by col1,  join table1 by col1
必须将数据加载两次,在进行内连接

4. 分片-复制连接 replicated join
 join_table = join big_table  by col1  ,  join small_table by col2   using 'replicated'

这样small_table 会加载到内存中复制到各个节点,再与big_table 连接。

replicated join 只支持内连接和左外连接


5. 倾斜数据连接 skew join

join_table = join table1 by col1,  join table2 by col2 using 'skewed'

先对table2的键值进行抽样,判断键值的分布情况,然后给各个Reducer分配键值范围,可能同一个键值被分配到好几个reducer中 


6. 排好顺序的数据连接 merge join

join_table = join table1 by col1,  join table2 by col2 using 'merge'


7. 笛卡尔积
cross table1, table2


Hive:

1. 内连接,可连接多个, 注意小表在前,大表在后

select * from  table1 a  join table2  b on a.col1=b.col2


2. 外连接

左:select * from  table1 a  left outer join table2  b on a.col1=b.col2

右:select * from  table1 a  right outer join table2  b on a.col1=b.col2
全:select * from  table1 a  full outer join table2  b on a.col1=b.col2


3. 左半开连接

select  a.col1  , a.col2 , a.col3  from  table1 a  left semi join table2  b on a.col1=b.col2

实现与内连接相同功能,但是比内连接高效。


4.笛卡尔积

select * from  table1  join table2   


5.map-side join

设置了 hive.auto.convert.join=true,   hive.mapjoin.smalltable.filesize=2500,  hive.optimize.bucketmapJoin=true 等参数会自动开启





转载于:https://www.cnblogs.com/leeeee/p/7276134.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值