前言

  前面一篇博文写的是Combiner优化MapReduce执行,也就是使用Combiner在map端执行减少reduce端的计算量。

  MapReduce程序的默认配置  

1)概述

  在我们的MapReduce程序中有一些默认的配置。所以说当我们程序如果要使用这些默认配置时,可以不用写。

  Hadoop(十七)之MapReduce作业配置与Mapper和Reducer类

  我们的一个MapReduce程序一定会有Mapper和Reducer,但是我们程序中不写的话,它也有默认的Mapper和Reducer。

  当我们使用默认的Mapper和Reducer的时候,map和reducer的输入和输出都是偏移量和数据文件的一行数据,所以就是相当于原样输出!

2)默认的MapReduce程序

Hadoop(十七)之MapReduce作业配置与Mapper和Reducer类
/**
* 没有指定Mapper和Reducer的最小作业配置
*/
public class MinimalMapReduce {
public static void main(String[] args) throws Exception{
// 构建新的作业
Configuration conf=new Configuration();
Job job = Job.getInstance(conf, "MinimalMapReduce");
job.setJarByClass(MinimalMapReduce.class);
// 设置输入输出路径
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
// ᨀ交作业运行
System.exit(job.waitForCompletion(true)?0:1);
  }
}
Hadoop(十七)之MapReduce作业配置与Mapper和Reducer类

  输入是:

    Hadoop(十七)之MapReduce作业配置与Mapper和Reducer类

  输出是:

    Hadoop(十七)之MapReduce作业配置与Mapper和Reducer类

二、作业的配置方式

  MapReduce的类型配置

  1)用于配置类型的属性

    Hadoop(十七)之MapReduce作业配置与Mapper和Reducer类

    Hadoop(十七)之MapReduce作业配置与Mapper和Reducer类

    在命令行中,怎么去配置呢?

      比如说mapreduce.job.inputformat.class。首先我们要继承Configured实现Tool工具才能这样去指定:

      -Dmapreduce.job.inputformat.class = 某一个类的类全名(一定要记得加报名)

    Hadoop(十七)之MapReduce作业配置与Mapper和Reducer类这是Map端的输出类型控制

    Hadoop(十七)之MapReduce作业配置与Mapper和Reducer类这是整个MapReduce程序输出类型控制,其实就是reduce的类型格式控制

  2)No Reducer的MapReduce程序--Mapper

    第一步:写一个TokenCounterMapper继承Mapper

Hadoop(十七)之MapReduce作业配置与Mapper和Reducer类
/**
* 将输入的文本内容拆分为word,做一个简单输出的Mapper
*/
public class TokenCounterMapper extends Mapper<LongWritable, Text, Text, IntWritable>{
private Text word=new Text();
private static final IntWritable one=new IntWritable(1);
@Override
protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, IntWritable>.Context context)
throws IOException, InterruptedException {
// TODO Auto-generated method stub
StringTokenizer itr=new StringTokenizer(value.toString());
while(itr.hasMoreTokens()){
word.set(itr.nextToken());
context.write(word, one);
        }
    }
}
Hadoop(十七)之MapReduce作业配置与Mapper和Reducer类

相关文章:

  • 2021-09-17
  • 2022-01-01
  • 2022-12-23
  • 2022-12-23
  • 2021-12-30
  • 2022-12-23
  • 2022-01-06
猜你喜欢
  • 2021-07-09
  • 2021-09-12
  • 2021-10-29
  • 2021-07-02
  • 2021-06-07
  • 2021-09-29
相关资源
相似解决方案