mapreduce去重

来源:互联网 发布:淘宝如何改价钱 编辑:程序博客网 时间:2024/04/27 17:55
我们知道,map处理之后,相同的key的值会被聚合起来,交给一个reduce处理,所以,我们可以把输出的内容作为输出的key,reduce原样输出key就OK,mapreduce的代码如下:
// map将输入中的value复制到输出数据的key上,并直接输出      public static class Map extends Mapper<Object, Text, Text, Text> {                    private static Text line = new Text();// 每行数据                    // 实现map函数          public void map(Object key, Text value, Context context)                  throws IOException, InterruptedException {              line = value;              context.write(line, new Text(""));          }      }        // reduce将输入中的key复制到输出数据的key上,并直接输出      public static class Reduce extends Reducer<Text, Text, Text, Text> {          // 实现reduce函数          public void reduce(Text key, Iterable<Text> values, Context context)                  throws IOException, InterruptedException {              context.write(key, new Text(""));          }      }  

0 0
原创粉丝点击