词频统计Map-Reduce过程
2016-04-28 10:17
561 查看
hdfs原始数据:
hello a
hello b
map阶段:
输入数据:key-value对,key为偏移量(一个字符一个偏移量,换行也算一个)
map输出数据为:
reduce阶段(首先对输入数据进行分组排序):
输入阶段:
输出阶段:
hello a
hello b
map阶段:
输入数据:key-value对,key为偏移量(一个字符一个偏移量,换行也算一个)
<0,"hello a"> <8,"hello b">
输出数据:context上下文,存储输出的数据(伪代码如下)
map(key,value,context) { String line = value; //hello a String[] words = value.split("\t"); for(String word : words) { //第一次hello //第一次a //第一次hello //第一次b context.write(word,1);//word为当前的词,1代表一次 } }
map输出数据为:
<hello,1> <a,1> <hello,1> <b,1>
reduce阶段(首先对输入数据进行分组排序):
输入阶段:
<a,1> <b,1> <hello,{1,1}>
输出阶段:
reduce(key,value,context) { int count = 0; String word = key; for(int i : value) { count +=i; } context.write(key,count); }
相关文章推荐
- Unity3D学习笔记(一)界面介绍
- 打开MySQL数据库远程访问的权限
- drawerlayout的使用
- mysql 触发器不能创建表
- MyEclipse+Tomcat+MAVEN+SVN项目完整环境搭建
- android手把手教你开发launcher(二)
- Caffe中的损失函数解析
- 使用Caffe复现DeepID实验
- oc基本动画实现
- Js中的继承
- spring配置文件详解
- load data infile into table 的使用例子
- java语言实现号码归属地查询
- Sublime text 2/3 中 Package Control 的安装与使用方法
- msserver 权限
- Python教程(一)Python简介
- [QTP/UFT12]无限延长试用期的方法
- 如何把图片存储到相册簿
- Oracle用户profile属性
- 50 Android Hack 读书笔记