如何在hadoop mapeduce中使用减速机

时间:2015-11-06 07:12:07

标签: hadoop mapreduce

您好我不熟悉使用reducer

将此视为我的输入文件

hi,how,1,a,b,are,you,xxx,xxxx,xxxxx
hi,how,1,a,b,are,you,xxx,xxxx,xxxxx
hi,how,1,a,b,i,am,yyyy,yyyy,yyyy
hi,how,1,a,b,i,am,yyyy,yyyy,yyyy
hi,how,2,a,b,are,you,xxx,xxxx,xxxxx
hi,how,2,a,b,are,you,xxx,xxxx,xxxxx
hi,how,2,a,b,i,am,yyyy,yyyy,yyyy
hi,how,3,a,b,are,you,yyyy,yyyy,yyyy
hi,how,3,a,b,i,am,yyyy,yyyy,yyyy
hi,how,4,a,b,are,you,yyyy,yyyy,yyyy
hi,how,4,a,b,are,you,yyyy,yyyy,yyyy
hi,how,4,a,b,i,am,xxx,xxxx,xxxxx

这是我的地图功能

@Override
        public  void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException 
        {
          String Str_line = value.toString();
          String[] input = Str_line.split(",");
          Text Outkey = new Text();
          Outkey.set(input[2]);
          context.write(Outkey),null);
         }

这是我的缩减功能

public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {

                context.write(key, null);
            }
  

我需要像这样的输出        嗨,怎么样,1,是,你        嗨,怎么样,1,我,我        嗨,怎么样,2,是,你        嗨,怎么样,2,我,我        嗨,怎么样,3,是        嗨,怎么样,3,我,我        嗨,怎么样,4,是,你        喜如何,4,I,是

1 个答案:

答案 0 :(得分:0)

映射器代码: -

  @Override
            public  void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException 
            {
              String Str_line = value.toString();
              String[] input = Str_line.split(",");

              Text Outkey = new Text();

              Outkey.set(input[0]+","+input[1]+","+input[2]+","+input[5]+","+input[6]);

              context.write(Outkey,NullWritable.get);
             }

减速机代码: -

 public void reduce(Text Key,Iterable<NullWritable> Values,Context context) throws IOException, InterruptedException {
       context.write(NullWritable.get(),key);

        }