hadoop编程(3)-MapReduce案例:文本去重
来源:互联网 发布:java线程机制 编辑:程序博客网 时间:2024/06/03 14:38
思路
把每行文本全部作为键,忽视值。
因为相同的键会发送给同一个Reduce任务进行归并,归并时同样key的所有value将归并为一个列表,当然我们并不关注这个列表,我们继续把key写出即可。
这个过程利用了MapReduce归并的特性自然对数据集去重。
代码
public class DistinctMapper extends Mapper<LongWritable,Text,Text,NullWritable>{ @Override protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { context.write(value,NullWritable.get()); } }
public class DistinctReducer extends Reducer<Text,NullWritable,Text,NullWritable> { @Override protected void reduce(Text key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException { context.write(key,NullWritable.get()); }}
单元测试代码
public class DistinctTest { MapReduceDriver<LongWritable, Text, Text, NullWritable, Text, NullWritable> mapReduceDriver; @Before public void setUp() { mapReduceDriver = MapReduceDriver.newMapReduceDriver(new DistinctMapper(), new DistinctReducer()); } @Test public void map() throws Exception { mapReduceDriver .withInput(new LongWritable(0), new Text("hello")) .withInput(new LongWritable(1), new Text("hello")) .withInput(new LongWritable(2), new Text("hi")) .withOutput(new Text("hello"), NullWritable.get()) .withOutput(new Text("hi"), NullWritable.get()) .runTest(); }}
阅读全文
0 0
- hadoop编程(3)-MapReduce案例:文本去重
- Hadoop MapReduce应用案例——数据去重
- MapReduce编程案例——数据去重
- hadoop mapreduce数据去重
- Hadoop MapReduce编程入门案例
- Hadoop MapReduce数据去重程序
- Hadoop 案例2----数据去重问题
- MapReduce编程之数据去重
- MapReduce编程实例之数据去重
- Hadoop mapreduce 数据去重 数据排序小例子
- Hadoop编程实例--数据去重
- MapReduce去重
- mapreduce去重
- Hadoop入门案例(二) 单词去重
- hadoop - MapReduce初级案例
- Hadoop-MapReduce应用案例
- Hadoop系列-MapReduce编程入门案例(八)
- hadoop编程(4)-MapReduce案例:求每一年的最高温度
- oracle 12c GI 执行root.sh脚本
- 解决onActivityResult()返回resultCode总是0的问题
- C语言入门——信号报告
- CentOs6.5安装Mysql-5.5.49
- day03-自定义struts2拦截器
- hadoop编程(3)-MapReduce案例:文本去重
- 基于阿里云容器服务的微服务实践
- java 枚举类型
- 程序显示烫烫烫,屯屯屯
- 221. Maximal Square
- 2017年十大移动应用开发的测试工具
- python str转换成float
- iptables配置详解
- String,StringBuffer,StringBuilder的区别