合并器实施和内部工作 [英] Combiner Implementation and internal working

查看:110
本文介绍了合并器实施和内部工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的MR代码中使用组合器,例如WordCount。



我应该如何实现它?

从组合器传递给reducer的数据是什么?



如果有人你可以为我提供Combiner和Reducer的代码。



如果你能解释组合器的工作方式会更好



我是mapreduce的新手,我处于学习阶段。

预先感谢:)

p>

解决方案

一个组合器,也称为半缩减器。

组合器的主要功能是使用相同的键汇总映射输出记录。

组合器类用于Map类和Reduce类之间,以减少 Map strong>和减少



具有示例代码的说明

输入:

 对象
是什么意思你对Java
有什么了解什么是Java虚拟机
如何启用Java高性能

MAP输出

 <什么,1> <做,1> <您,1> <平均,1> <通过,1> <对象,1> 
<什么1> <做,1> <您,1> <知,1> ≤约1> <爪哇,1>
<什么1> <是,1> <爪哇,1> <虚拟,1> <机,1>
< How,1> <爪哇,1> <启用,1> <高,1> <性能,1>

该MAP输出将作为输入传递给Combiner。

合并器输出

 <什么,1,1,1> <做,1,1 GT; <您,1,1 GT; <平均,1> <通过,1> <对象,1> 
<知道,1> ≤约1> <爪哇,1,1,1->
<是,1> <虚拟,1> <机,1>
< How,1> <启用,1> <高,1> <性能,1>

此组合器输出作为输入传递给Reducer。



Reducer输出

 <什么3> <做,2  - ; <您,2  - ; <平均,1> <通过,1> <对象,1> 
<知道,1> ≤约1> < Java,第3>
<是,1> <虚拟,1> <机,1>
如何,1> <启用,1> <高,1> <性能,1>

如果您使用java,下面的代码将设置Combiner& Reducer到同一类,这是理想的。

  job.setJarByClass(WordCount.class); 
job.setMapperClass(TokenizerMapper.class);
job.setCombinerClass(IntSumReducer.class);
job.setReducerClass(IntSumReducer.class);

查看工作示例


I want to use a combiner in my MR code say WordCount.

How should I implement it?

What sort of data is being passed to the reducer from the combiner?

It will be great if anyone of you can provide me codes of both Combiner as well as the Reducer.

It will be better if you can explain the way the combiner works

I am new to mapreduce and I am at a learning stage.

Thanks in advance :)

解决方案

A Combiner, also known as a semi-reducer.

The main function of a Combiner is to summarize the map output records with the same key.

The Combiner class is used in between the Map class and the Reduce class to reduce the volume of data transfer between Map and Reduce

Explanation with sample code.

MAP Input:

What do you mean by Object
What do you know about Java
What is Java Virtual Machine
How Java enabled High Performance

MAP output

<What,1> <do,1> <you,1> <mean,1> <by,1> <Object,1>
<What,1> <do,1> <you,1> <know,1> <about,1> <Java,1>
<What,1> <is,1> <Java,1> <Virtual,1> <Machine,1>
<How,1> <Java,1> <enabled,1> <High,1> <Performance,1>

This MAP output will be passed as input to Combiner.

Combiner output

   <What,1,1,1> <do,1,1> <you,1,1> <mean,1> <by,1> <Object,1>
   <know,1> <about,1> <Java,1,1,1>
   <is,1> <Virtual,1> <Machine,1>
   <How,1> <enabled,1> <High,1> <Performance,1>

This combiner output is passed as input to Reducer.

Reducer Output

   <What,3> <do,2> <you,2> <mean,1> <by,1> <Object,1>
   <know,1> <about,1> <Java,3>
   <is,1> <Virtual,1> <Machine,1>
   How,1> <enabled,1> <High,1> <Performance,1> 

If you are using java, below code will set Combiner & Reducer to same class, which is ideal.

  job.setJarByClass(WordCount.class);
  job.setMapperClass(TokenizerMapper.class);
  job.setCombinerClass(IntSumReducer.class);
  job.setReducerClass(IntSumReducer.class);

Have a look at working example in java @tutorialspoint

这篇关于合并器实施和内部工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆