zoukankan      html  css  js  c++  java
  • Hadoop_MapReduce中Mapper类和Reduce类

    在权威指南中,有个关于处理温度的MapReduce类,具体如下:

    第一部分:Map

    public class MaxTemperatureMapper extends MapReduceBase 

          implements Mapper<LongWritable,Text,Text,IntWritable>{

    //其他代码

    public void map(LongWritable key, Text value, OutputCollector<Text,IntWritable> output, Report reporter){

    //分析一下这四个参数

    该Mapper 接口是一个泛型类型,有四个形参类型,分别为:

      LongWritable key   Map函数的输入键

      Text value            Map函数的输入值

    OutputCollector<Text,IntWritable> output    输出键

    Report reporter   输出值

    }

    }

    PS :Hadoop 自身提供一套可优化网络序列化传输的基本类型,而不直接使用Java内嵌的类型。这些类型均在 org.apache.hadoop.io 包中。

      LongWritable 类型相当于Java中的Long类型

      Text类型相当于Java中的String类型

      IntWritable 类型相当于Java中的Integer类型

    第二部分:Reduce

    Reducer类的定义和使用

    public class MaxTemperatureReducer extends MapReduceBase 

            implements Reducer<Text, IntWritable, Text, IntWritable>{

    public void reduce(Text key, Iterable<IntWritabloe> values, Context context){

    }

    }

    pS: reduce 函数也有四个形式参数类型用于指定输入和输出类型。

    reduce函数的输入类型必须匹配map函数的输出类型。

    即Text类型和IntWritable 类型。

    第三部:运行MapReduce作业

    调用Job类的方法即可。

    Job对象指定作业执行规范。

  • 相关阅读:
    MyBatis动态SQL语句
    MyBatis分页
    理解 Linux 的处理器负载均值
    Linux命令之du
    Linux命令之df
    Linux命令之lsof
    maven打包加时间戳
    多线程学习-ListenableFuture使用介绍以及示例
    Host is not allowed to connect to this MySQL server解决方法
    Dapper,大规模分布式系统的跟踪系统
  • 原文地址:https://www.cnblogs.com/yytlmm/p/4837767.html
Copyright © 2011-2022 走看看