Spark:使用自定义分区程序强制两个 RDD[Key, Value] 与位于同一位置的分区

Spark: Force two RDD[Key, Value] with co-located partitions using custom partitioner

我有两个 RDD[K,V],其中 K=LongV=Object。让我们调用 rdd1rdd2。我有一个通用的自定义分区程序。我正在尝试通过避免或最小化数据移动来找到一种方法来采用 unionjoin

val kafkaRdd1 = /* from kafka sources */
val kafkaRdd2 = /* from kafka sources */

val rdd1 = kafkaRdd1.partitionBy(new MyCustomPartitioner(24))
val rdd2 = kafkaRdd2.partitionBy(new MyCustomPartitioner(24))

val rdd3 = rdd1.union(rdd2) // Without shuffle
val rdd3 = rdd1.leftOuterjoin(rdd2) // Without shuffle

在同一个 slave 节点上假定(或强制执行)rdd1rdd2nth-Partition 是否安全?

不可能在 Spark 中强制*托管,但您使用的方法将最大限度地减少数据移动。创建 PartitionerAwareUnionRDD 后,将分析输入 RDDs 以根据每个位置的记录数选择最佳输出位置。有关详细信息,请参阅 getPreferredLocations 方法。


* 根据High Performance Spark

Two RDDs will be colocated if they have the same partitioner and were shuffled as part of the same action.