首页 > 其他 > 详细

Hive差集运算详解

时间:2018-01-17 16:30:24      阅读:222      评论:0      收藏:0      [点我收藏+]

差集定义:一般地,设A,B是两个集合,由所有属于A且不属于B的元素组成的集合,叫做集合A减集合B(或集合A与集合B之差),类似地,对于集合A.B,我们把集合{x/x∈A,且x¢B}叫做A与B的差集,记作A-B记作A-B(或A\B),即A-B={x|x∈A,且x ¢B}(或A\B={x|x∈A,且x ¢B} B-A={x/x∈B且x¢A} 叫做B与A的差集

技术分享图片

 

 

下面来介绍一下hive常用的求差集方法,左(右)连接 left (outer) join

先看一下左连接之后表是什么样的

1 hive> select * from A a left outer join B b on a.uid=b.uid and a.goods=b.goods;
2 1    2    1    2
3 1    3    NULL    NULL
4 2    1    NULL    NULL
5 2    3    2    3
6 3    1    NULL    NULL
7 Time taken: 12.735 seconds, Fetched: 5 row(s)

 

现在只要取出B的uid和goods为null的行就可以了

 

1 hive> select a.* from A a left outer join B b on a.uid=b.uid and a.goods=b.goods where b.uid is null and b.goods is null;
2 1    3
3 2    1
4 3    1
5 Time taken: 13.023 seconds, Fetched: 3 row(s)

 

 

部分引用:http://blog.csdn.net/dr_guo/article/details/51182626

 

Hive差集运算详解

原文:https://www.cnblogs.com/hangaozu/p/8303520.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!