spark算子cogroup讲解

  • Post author:
  • Post category:其他



1.cogroup是什么

cogroup定义如下:

def
cogroup[W1, W2](other1: RDD[(K, W1)], other2: RDD[(K, W2)], numPartitions: Int): RDD[(K, (Iterable[V], Iterable[W1], Iterable[W2]))]
 Permalink
For each key k in this or other1 or other2, return a resulting RDD that contains a tuple with the list of values for that key in this, other1 and other2.

对于每一个k,在other1或者other2里边都可以,返回一个结果RDD,包含了一个元组,元组里面的每一个key,对应每一个other1,other2。


2.产生两个RDD

val rdd1 = sc.parallelize(Array(("aa",1),("bb",2),("cc",6)))
val rdd2 = sc.parallelize(Array(("aa",3),("dd",4),("aa",5)))


3.进行cogroup操作

val rdd3 = rdd1



版权声明:本文为RiverCode原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。