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基本数据读取,通俗易懂。 此项目情景为,遗传关系族谱。 (爷爷 、父母 、孩子) 经典案例
mapreduce案例测试数据
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文件,其他包都需要自己导入。
基于MapReduce的气候数据分析 是一个旨在通过大数据处理技术深入理解和分析气候数据的研究课题。该课题利用MapReduce编程模型,针对包括温度、湿度、风速等在内的多种气象参数进行处理,以应对传统方法在处理大规模...
数据格式为:用户标识 设备标识 基站位置 通讯的日期 通讯时间 example: 0000009999 0054785806 00000089 2016-02-21 21:55:37 需要得到的数据格式为: 用户标识 时段 基站位置 停留时间 example: ...