ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

MapReduce当中Combiner的用法

2021-10-31 12:36:29  阅读:218  来源: 互联网

标签:Combiner MapReduce value 用法 key org apache import hadoop


马克-to-win @ 马克java社区:防盗版实名手机尾号:73203。在上一章的helloworld例子中,每一个map都可能会产生大量的本地输出,这些输出会通过网络到达reducer端,这样会非常浪费带宽。解决这个问题可以通过Combiner。Combiner的作用就是对map端的输出先做一次合并,是MapReduce的一种优化手段之一。

package com;
import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Partitioner;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;
 
public class WordCountMark_to_win {

    public static class TokenizerMapper extends Mapper<Object, Text, Text, IntWritable> {
        private IntWritable one = new IntWritable(1);
        private Text word = new Text();

        public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
            System.out.println("key is 马克-to-win @ 马克java社区:防盗版实名手机尾号:73203"+key.toString()+" value is "+value.toString());
            StringTokenizer itr = new StringTokenizer(value.toString());
            while (itr.hasMoreTokens()) {
                word.set(itr.nextToken());
                context.write(word, one);
            }
        }
    }

    public static class PartitionClass extends Partitioner<Text, IntWritable>
    {
/*
int com.WordCount.PartitionClass.getPartition(Text key, IntWritable value, int numPartitions)
Get the partition number for a given key (hence record) given the total number of partitions i.e. number of reduce-tasks for the job.
Parameters:key the key to be partioned.value the entry value.numPartitions the total number of partitions.
Returns:the partition number for the key.
*/       

更多内容请见原文,文章转载自:https://blog.csdn.net/qq_44594249/article/details/96327542

标签:Combiner,MapReduce,value,用法,key,org,apache,import,hadoop
来源: https://www.cnblogs.com/xiaolongxia1922/p/15488985.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有