distinct

 

 

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


object distinctRDD {
  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)
    
    
    //val distinctRDD: RDD[Int] = listRDD.distinct()
    
    //distinct算子可以对数据去重,由于去重后导致数据减少,可以改变分区
    val distinctRDD: RDD[Int] = listRDD.distinct(2)

    distinctRDD.saveAsTextFile("output")









  }


}

 

上一篇:340. Longest Substring with At Most K Distinct Characters


下一篇:第七天