Spark join算子学习使用详解
作者:高景洋 日期:2020-10-25 14:07:52 浏览次数:2069
join:
关联查询
Spark 中的Rdd关联可以通过 4种方式
1、Join
2、leftOuterJoin
3、rightOuterJoin
4、fullOuterJoin
示例代码:
def my_join(): rdd_a = sc.parallelize([('A','a1'),('C','c1'),('D','d1'),('F','f1'),('F','f2')]) rdd_b = sc.parallelize([('A','a2'),('C','c2'),('C','c3'),('E','e1')]) result = rdd_a.join(rdd_b)
print(result.collect())
result_left_join = rdd_a.leftOuterJoin(rdd_b)
print(result_left_join.collect())
result_right_join = rdd_a.rightOuterJoin(rdd_b)
print(result_right_join.collect())
result_full_join = rdd_a.fullOuterJoin(rdd_b)
print(result_full_join.collect())
输出结果:
[('A', ('a1', 'a2')), ('C', ('c1', 'c2')), ('C', ('c1', 'c3'))] [('A', ('a1', 'a2')), ('F', ('f1', None)), ('F', ('f2', None)), ('D', ('d1', None)), ('C', ('c1', 'c2')), ('C', ('c1', 'c3'))] [('A', ('a1', 'a2')), ('C', ('c1', 'c2')), ('C', ('c1', 'c3')), ('E', (None, 'e1'))] [('A', ('a1', 'a2')), ('F', ('f1', None)), ('F', ('f2', None)), ('D', ('d1', None)), ('C', ('c1', 'c2')), ('C', ('c1', 'c3')), ('E', (None, 'e1'))]
本文永久性链接:
<a href="http://r4.com.cn/art156.aspx">Spark join算子学习使用详解</a>
<a href="http://r4.com.cn/art156.aspx">Spark join算子学习使用详解</a>
当前header:Host: r4.com.cn
X-Host1: r4.com.cn
X-Host2: r4.com.cn
X-Host3: 127.0.0.1:8080
X-Forwarded-For: 18.221.147.141
X-Real-Ip: 18.221.147.141
X-Domain: r4.com.cn
X-Request: GET /art156.aspx HTTP/1.1
X-Request-Uri: /art156.aspx
Connection: close
Accept: */*
User-Agent: Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Accept-Encoding: gzip, br, zstd, deflate