【发布时间】:2017-10-19 17:41:27
【问题描述】:
我需要压缩两个可能有也可能没有相同分区的rdd,因此寻找重新分区的方法。我需要在压缩时保持顺序,而且我通常知道重新分区洗牌。但是下面的代码显示 repartiton(1) 没有改组 rdd。是只有这一次还是我们每次都能保证?
repartition(1) 是否类似于 .collect 因为它们都将 rdd 带到单个节点??
scala> var k = sc.parallelize((1 to 100),4)
k: org.apache.spark.rdd.RDD[Int] = ParallelCollectionRDD[0] at parallelize at <console>:27
scala> k.repartition(2)
res0: org.apache.spark.rdd.RDD[Int] = MapPartitionsRDD[4] at repartition at <console>:30
scala> res0.collect
res1: Array[Int] = Array(1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99)
scala> var l = sc.parallelize((1 to 100),4)
l: org.apache.spark.rdd.RDD[Int] = ParallelCollectionRDD[11] at parallelize at <console>:27
scala> l.repartition(1)
res5: org.apache.spark.rdd.RDD[Int] = MapPartitionsRDD[15] at repartition at <console>:30
scala> .collect
res6: Array[Int] = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100)
【问题讨论】:
标签: scala apache-spark rdd