Sortby

 

 行动算子

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

object sortByRDD {
  def main(args: Array[String]): Unit = {

    val conf: SparkConf = new SparkConf().setAppName("My scala word count").setMaster("local")
    val sc = new SparkContext(conf)

    val rdd1: RDD[Int] = sc.makeRDD(1 to 16,4)
    val sortByRDD1: RDD[Int] = rdd1.sortBy(x=>x,ascending = false)
    val sortByRDD2: RDD[Int] = rdd1.sortBy(x=>x%2)

    sortByRDD1.collect().foreach(println)
    sortByRDD2.collect().foreach(println)


  }

}

 

posted on 2020-09-21 17:54  happygril3  阅读(229)  评论(0)    收藏  举报

导航