广元 网站建设十堰网络科技公司排名
news/
2025/9/23 7:39:33/
文章来源:
广元 网站建设,十堰网络科技公司排名,网页设计六安模板,全国教育平台网站建设learn from 从0开始学大数据#xff08;极客时间#xff09; MapReduce 编程模型
包含 Map 和 Reduce 两个过程
map 的主要输入是一对 Key, Value 值#xff0c;输出一对 Key, Value 值将相同 Key 合并#xff0c;形成 Key, Value 集合 再将这个… learn from 从0开始学大数据极客时间 MapReduce 编程模型
包含 Map 和 Reduce 两个过程
map 的主要输入是一对 Key, Value 值输出一对 Key, Value 值将相同 Key 合并形成 Key, Value 集合 再将这个 Key, Value 集合 输入 reduce输出零个或多个 Key, Value 对
// 计算单词数量的 MapReduce 版本
public class WordCount {public static class TokenizerMapperextends MapperObject, Text, Text, IntWritable{private final static IntWritable one new IntWritable(1);private Text word new Text();// map 函数 public void map(Object key, Text value, Context context) throws IOException, InterruptedException {StringTokenizer itr new StringTokenizer(value.toString());while (itr.hasMoreTokens()) {word.set(itr.nextToken());context.write(word, one);// 对每个单词输出一个 word, 1 的键值对}}}// MR 计算框架会将这些 word, 1 收集起来// 将相同的 word 放在一起形成 word , 1,1,1,1,1,1,1… 这样的 Key, Value 集合 数据// 然后将其输入给 reduce 函数public static class IntSumReducerextends ReducerText,IntWritable,Text,IntWritable {private IntWritable result new IntWritable();// reduce 函数public void reduce(Text key, IterableIntWritable values,Context context) throws IOException, InterruptedException {int sum 0;for (IntWritable val : values) {sum val.get();// 对 word 对应的 1 的集合 求和 sum}result.set(sum);context.write(key, result);// 输出 word, sum 键值对}}
}
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/911801.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!