import java.io.IOException;

 import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
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.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
public class Dedpu extends Configured implements Tool {
/**
* 数据去重
* 数据样例:
* 输入数据
* 2006-6-9 a
* 2006-6-10 b
* 2006-6-9 a
* 结果数据
* 2006-6-9 a
* 2006-6-10 b
* 设计思路:
* Map阶段 <时间,字符>
* Reduce阶段输入<时间,list<字符>>,去除重复的字符,输出
*
* **/
public static class Map extends Mapper<LongWritable,Text,Text,Text>{
public void map(LongWritable key,Text value,Context context)throws IOException, InterruptedException{
String line=value.toString();
Text myvalue=new Text("");
context.write(new Text(line), myvalue);
// StringTokenizer tokenizer=new StringTokenizer(line);
// String datestr="",datastr="";
// while(tokenizer.hasMoreTokens())
// {
// datestr=tokenizer.nextToken();
// datastr=tokenizer.nextToken();
// context.write(new Text(datestr), new Text(datastr));
//
// }
} } public static class Reduce extends Reducer<Text,Text,Text,Text>{
public void reduce(Text key,Iterable<Text>values,Context context)throws IOException,InterruptedException{ context.write(key, new Text(""));
// ArrayList arr=new ArrayList();
// Text mykey=key;
// for(Text txt:values)
// {
//
// if(!arr.contains(txt.toString())){
// arr.add(txt.toString());
// }
//
//
// }
// for(int i=0;i<arr.size();i++){
// context.write(mykey, new Text(arr.get(i).toString()));
//
// } } } public int run(String[] args)throws Exception
{
Configuration conf=new Configuration();
Job job=new Job(conf,"Data Depution");
job.setJarByClass(Dedpu.class); job.setMapperClass(Map.class);
job.setCombinerClass(Reduce.class);
job.setReducerClass(Reduce.class); job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class); job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class); FileInputFormat.setInputPaths(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1])); boolean success=job.waitForCompletion(true);
return success?0:1; } public static void main(String[] args) throws Exception{
int ret=ToolRunner.run(new Dedpu(), args);
System.exit(ret);
}
}

map/reduce实现数据去重的更多相关文章

  1. Map/Reduce个人实战--生成数据测试集

    背景: 在大数据领域, 由于各方面的原因. 有时需要自己来生成测试数据集, 由于测试数据集较大, 因此采用Map/Reduce的方式去生成. 在这小编(mumuxinfei)结合自身的一些实战经历, ...

  2. Hadoop 少量map/reduce任务执行慢问题

    最近在做报表统计,跑hadoop任务. 之前也跑过map/reduce但是数据量不大,遇到某些map/reduce执行时间特别长的问题. 执行时间长有几种可能性: 1. 单个map/reduce任务处 ...

  3. Map/Reduce 工作机制分析 --- 数据的流向分析

    前言 在MapReduce程序中,待处理的数据最开始是放在HDFS上的,这点无异议. 接下来,数据被会被送往一个个Map节点中去,这也无异议. 下面问题来了:数据在被Map节点处理完后,再何去何从呢? ...

  4. 基于python的《Hadoop权威指南》一书中气象数据下载和map reduce化数据处理及其可视化

    文档内容: 1:下载<hadoop权威指南>中的气象数据 2:对下载的气象数据归档整理并读取数据 3:对气象数据进行map reduce进行处理 关键词:<Hadoop权威指南> ...

  5. 第十篇:Map/Reduce 工作机制分析 - 数据的流向分析

    前言 在MapReduce程序中,待处理的数据最开始是放在HDFS上的,这点无异议. 接下来,数据被会被送往一个个Map节点中去,这也无异议. 下面问题来了:数据在被Map节点处理完后,再何去何从呢? ...

  6. 机器学习等知识--- map/reduce, python 读json数据。。。

    map/ reduce 了解: 简单介绍map/reduce 模式: http://www.csdn.net/article/2013-01-07/2813477-confused-about-map ...

  7. List<Map>中根据map的同一指标项数据——去重代码

    先看网络上,博客经常出现的错误代码: for(ABatchAddCheckVO aBatchAddCheckVO : addList){ dto.put("aac001",aBat ...

  8. 入门大数据---Map/Reduce,Yarn是什么?

    简单概括:Map/Reduce是分布式离线处理的一个框架. Yarn是Map/Reduce中的一个资源管理器. 一.图形说明下Map/Reduce结构: 官方示意图: 另外还可以参考这个: 流程介绍: ...

  9. [Hadoop]-从数据去重认识MapReduce

    这学期刚好开了一门大数据的课,就是完完全全简简单单的介绍的那种,然后就接触到这里面最被人熟知的Hadoop了.看了官网的教程[吐槽一下,果然英语还是很重要!],嗯啊,一知半解地搭建了本地和伪分布式的, ...

随机推荐

  1. centOS tengine 安装后 不能访问的问题

    1 安装方式跟在ubuntu下 安装一样.因为都是用源码 2  但安装好以后发现,局域网电脑访问不了!.原以为是安装错了.又装了一遍,还是不行,最终是iptables 没开放80端口... http: ...

  2. PHP 插入排序法

    <?php function insertSort($arr) { //区分 哪部分是已经排序好的 //哪部分是没有排序的 //找到其中一个需要排序的元素 //这个元素 就是从第二个元素开始,到 ...

  3. web系列教程之php 与mysql 动态网站 。检索 与更新。

    接着上次WEb 系列开发之php 与mysql动态网站入门. 个人觉得,学习技术就像一棵大树,主干很重要,枝叶其次.对于学习技术,我们应该分清主次关系.怎么学?为什么要学?有一个较好的分寸. 有时候觉 ...

  4. HDU 1166 敌兵布阵 线段树的基本应用——动态区间和问题

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=1166 简单题,1A了,这个好像就是传说中的“点树”. 设当前结点表示线段[left, right],编号 ...

  5. 在ajax当中使用url重写来避免url的暴露

    记得一次面试,有这样一道面试题:jsp页面当中需要用到ajax的实现,此时需要调用java的url:此时的问题是如果用户查看页面源码就能看到真是的url,这个问题如何避免.说实话,AJAX我用的只是皮 ...

  6. spring 下载地址(拷贝)

    Spring2.5.6 和Spring3.0.5所有jar下载地址spring jar包 官方下载地址 文档下载地址.2.56版本 和3.05版本http://s3.amazonaws.com/dis ...

  7. Error Code: 1064 – You have an error in your SQL syntax解决几个方法

    本文转自 http://www.anyiwa.com/?p=1066 Error Code: 1064 – You have an error in your SQL syntax解决几个方法 十一月 ...

  8. ajax跨域调用

    http://redsky008.iteye.com/blog/1754328 http://www.cnblogs.com/mahatmasmile/archive/2013/03/29/29895 ...

  9. Mybatis 学习

    1.  Mybatis 中 # 与 $ 符号的区别: a.    #将传入的数据都当成一个字符串,会对自动传入的数据加一个双引号. 如:order by #user_id#,如果传入的值是12,那么解 ...

  10. hdu 4433

    一道dp题,虽然知道是dp,但是不会做: 学习了ACM_cxlove大神的代码,终于明白了: 搬运工: dp[i][j][k]表示 前i个已经完全匹配,而这时候,第i+1个已经加了j位,第i+2位已经 ...