Mapreduce《案例之数据去重复》
源数据:
a.txt内容:
2012-3-1 b
2012-3-2 a
2012-3-3 b
2012-3-4 d
2012-3-5 a
2012-3-6 c
2012-3-7 d
2012-3-3 c
b.txt内容:
2012-3-1 a
2012-3-2 b
2012-3-3 c
2012-3-4 d
2012-3-5 a
2012-3-6 b
2012-3-7 c
2012-3-3 c
输出结果:
2012-3-1 a
2012-3-1 b
2012-3-2 a
2012-3-2 b
2012-3-3 b
2012-3-3 c
2012-3-4 d
2012-3-5 a
2012-3-6 b
2012-3-6 c
2012-3-7 c
2012-3-7 d
//===================================JAVA CODE=========================
package gq;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
/**
* 数据去重复
* @author tallqi
*
*/
public class Dereplication {
public static class Map extends Mapper<Object, Text, Text, Text>{
private static Text line = new Text();
public void map(Object key,Text value,Context context) throws IOException, InterruptedException{
line =value;
System.out.println("Map:"+value);
context.write(line, new Text(""));
}
}
public static class Reduce extends Reducer<Text, Text, Text, Text>{
public void reduce(Text key,Iterable<Text> value,Context context) throws IOException, InterruptedException{
System.out.println("Reduce:"+key);
context.write(key, new Text(""));;
}
}
public static void main(String[] args) throws Exception{
Configuration conf = new Configuration();
Job job = new Job(conf,"Dereplication");
job.setJarByClass(Dereplication.class);
//设置Map、Combine和Reduce处理类
job.setMapperClass(Map.class);
// job.setCombinerClass(Reduce.class);
job.setReducerClass(Reduce.class);
//输出Key,value的类型
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
//数据源地址,数据输出地址
FileInputFormat.addInputPath(job, new Path("hdfs://h0:9000/user/tallqi/in/input"));
FileOutputFormat.setOutputPath(job, new Path("hdfs://h0:9000/user/tallqi/in/output"));
System.exit(job.waitForCompletion(true)?0:1);
}
}
相关推荐
mapreduce案例测试数据
mapreduce案例测试数据
mapreduce基本数据读取,通俗易懂。 此项目情景为,遗传关系族谱。 (爷爷 、父母 、孩子) 经典案例
mapreduce案例测试数据
了解map和reduce工作原理,以及排序,分组,分区设置,有详细的注释,方便查看学习,适合入门初学者练手
MapReduce操作实例-数据去重.pdf 学习资料 复习资料 教学资源
mapreduce案例数据:dept.csv,emp.csv,sales.csv
大数据mapreduce案例介绍,包括代码解释,详解MRS工作流程
【MapReduce篇07】MapReduce之数据清洗ETL1
1.社交网络综合评分案例 2.微博精准营销案例 3.物品推荐案例 4.QQ好友推荐案例
MapReduce求取行平均值 MapReduce小实例 数据有经过处理已经添加行号的 也有未添加的 行平均值的四种求法
2-MapReduce案例.docx2-MapReduce案例.docx2-MapReduce案例.docx2-MapReduce案例.docx2-MapReduce案例.docx2-MapReduce案例.docx2-MapReduce案例.docx2-MapReduce案例.docx2-MapReduce案例.docx2-MapReduce案例.docx
mapreduce的Wordcount案例将main生成jar可直接在hdfs上运行
一次很好的mapreduce框架学习。复习了框架大部分组件,代码都是一个一个敲上去的,借鉴了视频中老师的讲解,只包含了7个代码中关键的java文件,其他包都需要自己导入。
数据格式为:用户标识 设备标识 基站位置 通讯的日期 通讯时间 example: 0000009999 0054785806 00000089 2016-02-21 21:55:37 需要得到的数据格式为: 用户标识 时段 基站位置 停留时间 example: ...
MapReduce求行平均值--标准差--迭代器处理--MapReduce案例
前四节提供了几个小案例 下面详细介绍MapReduce中Map任务Reduce任务以及MapReduce的执行流程。 Map任务: 读取输入文件内容,解析成key,value对。对输入文件的每一行,解析成key,value对。每一个键值对调用一次map...
为MapReduce框架对电话号码的上行流量和下行流量及总流量进行统计的模板数据
08.mapreduce编程案例--流量统计求和--自定义数据类型.mp4
整理了MapRduce的几个入门案例,提供源数据 案例分为: 1、统计单词的个数 2、设置分区 3、统计json数据 4、统计并排序 5、mapReducer找朋友的使用