spark 通过隐式值排序 Ordering.on

 

 

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

    val sparkConf = new SparkConf().setMaster("local[2]").setAppName("customersort1")
    val sc = new SparkContext(sparkConf)
    val girlInfo = sc.parallelize(Array("xiaoming 90 31","xiong 90 32","dabai 80 34","polu 98 35"))
    val pesion = girlInfo.map(x=>
      {
      val arr = x.split(" ")
      val name = arr(0)
      val age = arr(2).toInt
      val fv = arr(1).toInt
       (name,fv,age)
       })

    //隐式值    //[(Int,Int)  要比较的参数    
//按照fv正排序,如果fv 相同 按照 age 反排序 (x._2,-x._3)
implicit val oder= Ordering[(Int,Int)].on[(String,Int,Int)](x=>(x._2,-x._3)) val buffer = pesion.sortBy(x=>x).collect.toBuffer println(buffer) sc.stop() } }

 

上一篇:课程主页之课程页面


下一篇:[区块链] 如何在Corda上写一个派息的Dapp