coalesce

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}


object coalesceRDD {
  def main(args: Array[String]): Unit = {
    //本地模式
    val conf: SparkConf = new SparkConf().setAppName("My scala word count").setMaster("local")

    //创建spark上下文对象
    val sc = new SparkContext(conf)



    val listRDD: RDD[Int] = sc.makeRDD(List(1,3,5,3,6,2,1),4)
    println(listRDD.partitions.size)
    //coalesce重新分区,可以选择是否进行shuffle过程,有参数shuffle决定
    val coalesceRDD: RDD[Int] = listRDD.coalesce(3)
    //repartition调用coalesce(shuffle=True)
    val repartitionRDD: RDD[Int] = listRDD.repartition(3)
    println(coalesceRDD.partitions.size)
    println(repartitionRDD.partitions.size)





  }


}

 

posted on 2020-09-18 19:06  happygril3  阅读(255)  评论(0)    收藏  举报

导航