MapReduce工作原理
Map-Reduce框架的运作完全基于<key,value>对,即数据的输入是一批<key,value>对,生成的结果也是一批<key,value>对,只是有时候它们的类型不一样而已。Key和value的类由于需要支持被序列化(serialize)操作,所以它们必须要实现Writable接口,而且key的类还必须实现WritableComparable接口,使得可以让框架对数据集的执行排序操作。
一个Map-Reduce任务的执行过程以及数据输入输出的类型如下所示:
(input)<k1,v1> -> map -> <k2,v2> -> combine -> <k2,v2> -> reduce -> <k3,v3>(output)
下面通过一个的例子并结合源代码来详细说明这个过程
这也是Hadoop自带的一个例子,目标是统计文本文件中单词的个数。
假设有如下的两个文本文件来运行WorkCount程序:
Hello Hadoop GoodBye Hadoop
|
Hadoop针对文本文件缺省使用LineRecordReader类来实现读取,一行一个key/value对,key取偏移量,value为行内容。
如下是map1的输入数据:
Key1
|
Value1
|
0
|
Hello World Bye World
|
如下是map2的输入数据:
Key1
|
Value1
|
0
|
Hello Hadoop GoodBye Hadoop
|
3.3 map输出/combine输入
如下是map1的输出结果
Key2
|
Value2
|
Hello
|
1
|
World
|
1
|
Bye
|
1
|
World
|
1
|
如下是map2的输出结果
Key2
|
Value2
|
Hello
|
1
|
Hadoop
|
1
|
GoodBye
|
1
|
Hadoop
|
1
|
Combiner类实现将相同key的值合并起来,它也是一个Reducer的实现。
如下是combine1的输出
Key2
|
Value2
|
Hello
|
1
|
World
|
2
|
Bye
|
1
|
如下是combine2的输出
Key2
|
Value2
|
Hello
|
1
|
Hadoop
|
2
|
GoodBye
|
1
|
Reducer类实现将相同key的值合并起来。
如下是reduce的输出
Key2
|
Value2
|
Hello
|
2
|
World
|
2
|
Bye
|
1
|
Hadoop
|
2
|
GoodBye
|
1
|
即实现了WordCount的处理。
分享到:
相关推荐
The Annotated Turing: A Guided Tour through Alan Turing's Historic Paper on Computability and the Turing Machine Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN ...
annotated_nginx Annotated Nginx Source(中文) 简介 Nginx源码分析,注解代码,帮助学习Nginx。 1.10增加了动态模块、http2、reuseport。 1.11.x里的stream模块的变动较大,完善了阶段处理。 1.14增加了mirror...
人脸数据库 人脸图像 Annotated Database 240幅图像
the annotated STL source the annotated STL source
the.annotated.turing
IMM Annotated Database 人脸数据库 全部240副图像
python-2.5-annotated 记录阅读代码时的评注. bugfix: 修复svnversion产生的版本信息中包含空格导致无法编译的bug. commit 《Python源码剖析》附书代码: code-reading/pythonympx.rar code-reading/pythonympx.tar....
副标题:他的生平、思想及论文解读原作名: The Annotated Turing作者: Charles Petzold图灵机是英国数学家阿兰·麦席森·图灵提出的一种抽象计算模型,本书深入剖析了图灵这篇描述图灵机和可计算性的原始论文《论可...
mysql3注释 mysql原始注解
Annotated Lucene 中文版 Lucene源码剖析
The Annotated C++ Reference Manual 一共四个压缩包
Thinking in Java 4th Edition Annotated Solutions Guide!
Thinking in c++ Annotated Solution Guide 答案
redis-3.0-annotated-unstable.zipredis-3.0-annotated-unstable.zipredis-3.0-annotated-unstable.zipredis-3.0-annotated-unstable.zip
The Annotated C++ Reference Manual.part2
The Common Language Infrastructure Annotated Standard
Dotnet framework standard library annotated reference
Thinking_in_C++Annotated+Solution+Guide+for_Vol1 Thinking_in_C++课后题答案
The Annotated C++ Reference Manual
The Annotated C++ Reference Manual 英文 PDF 复印扫描版 part1 Bjarne Stroustrup 差 part2下载地址 http://download.csdn.net/detail/sfgassdfg/9572821 part3下载地址 ...