import Utils.SparkUtils
import org.apache.spark.SparkContext
import org.apache.spark.rdd.RDD
object IndexDemo {
def main(args: Array[String]): Unit = {
val sc: SparkContext = SparkUtils.getSparkContext()
val rdd: RDD[Int] = sc.makeRDD(List(1,2,3,4),2)
val rdd1: RDD[(Int, Int)] = rdd.mapPartitionsWithIndex((p, mp)=>{
for(elem<-mp) yield (p,elem)
})
rdd1.foreach(println)
sc.stop()
}
}
MapPartitionsWitnIndex算子
最新推荐文章于 2024-09-04 15:35:48 发布