zoukankan      html  css  js  c++  java
  • Scala实现Mapreduce程序3----数据排序

    输入n个数字,输出每一个数字以及其排名例如:

    4

    2

    3

    1

    输出:

    1  1

    2  2

    3  3

    4  4

    scala实现

    package HadoopvsSpark.ScalaMap

    import org.apache.spark.{HashPartitioner, SparkConf, SparkContext}

    /**
    * Created by Administrator on 2017/5/25.
    */
    object Sorted {
    def main(args: Array[String]): Unit = {
    val conf=new SparkConf().setMaster("")
    val sc=new SparkContext(conf)
    val one=sc.textFile("")
    var index=0;
    //由于输入文件有多个,产生不同的分区,为了生产序号,使用HashPartitioner将中间的RDD归约到一起。
    val line=one.filter(_.trim.length>0).map(num=>(num.trim.toInt,"")).partitionBy(new HashPartitioner(1)
    ).sortByKey().map(t=>{
    index+=1
    (index,t._1)
    }).collect().foreach(x=>println(x._1+" "+x._2))
    }

    }
  • 相关阅读:
    @bzoj
    @hdu
    @noi.ac
    @noi.ac
    @noi.ac
    jsp include page指令标记
    javascript 对象(DOM)document window history
    HTML 标准属性 和 事件属性
    html 特殊字符 fmt table A
    mysql 启动 导入sql文件
  • 原文地址:https://www.cnblogs.com/sunt9/p/6936412.html
Copyright © 2011-2022 走看看