大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全家桶1年46,售后保障稳定
Spark pyspark rdd连接函数之join、leftOuterJoin、rightOuterJoin和fullOuterJoin介绍
例子:
1)数据初始化
>>> pp=(('cat', 2), ('cat', 5), ('book', 4), ('cat', 12))
>>> pp
(('cat', 2), ('cat', 5), ('book', 4), ('cat', 12))
>>> qq=(("cat",2), ("cup", 5), ("mouse", 4),("cat", 12))
>>> qq
(('cat', 2), ('cup', 5), ('mouse', 4), ('cat', 12))
>>> pairRDD1 = sc.parallelize(pp)
>>> pairRDD2 = sc.parallelize(qq)
>>> pairRDD1.collect()
[('cat', 2), ('cat', 5), ('book', 4), ('cat', 12)]
>>> pairRDD2.collect()
[('cat', 2), ('cup', 5), ('mouse', 4), ('cat', 12)]
>>> pairRDD1.join(pairRDD2).collect()
[('cat', (2, 2)), ('cat', (2, 12)), ('cat', (5, 2)), ('cat', (5, 12)), ('cat', (12, 2)), ('cat', (12, 12))]
>>> pairRDD1.leftOuterJoin(pairRDD2).collect()
[('book', (4, None)), ('cat', (2, 2)), ('cat', (2, 12)), ('cat', (5, 2)), ('cat', (5, 12)), ('cat', (12, 2)), ('cat', (12, 12))]
>>> pairRDD1.rightOuterJoin(pairRDD2).collect()
[('cup', (None, 5)), ('mouse', (None, 4)), ('cat', (2, 2)), ('cat', (2, 12)), ('cat', (5, 2)), ('cat', (5, 12)), ('cat', (12, 2)), ('cat', (12, 12))]
>>> pairRDD1.fullOuterJoin(pairRDD2).collect()
[('book', (4, None)), ('cup', (None, 5)), ('mouse', (None, 4)), ('cat', (2, 2)), ('cat', (2, 12)), ('cat', (5, 2)), ('cat', (5, 12)), ('cat', (12, 2)), ('cat', (12, 12))]
6)union结果:
>>> pairRDD1.union(pairRDD2).collect()
[('cat', 2), ('cat', 5), ('book', 4), ('cat', 12), ('cat', 2), ('cup', 5), ('mouse', 4), ('cat', 12)]
参考:http://blog.cheyo.net/175.html
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/216256.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...