我的hadoop初学程序------简单数据去重--------Deduplication
2013-10-13 16:55
399 查看
package bin; 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; import org.apache.hadoop.util.GenericOptionsParser; public class Deduplication { //描述:数据去重程序 //数据的每一行作为一项输入,那么要知道map的功能以及reduce的功能 //map:提取出整个文件中的有用内容,即---键值对<key,value>--- //map提取出的原始的键值对,经过合并,形成同一个key的所有value集<key,[value1,value2,value3,...]>----它是作为reduce的输入的 //即,reduce的输入是一个特定类型的key,还有一个values集合。 //reduce针对每一个key处理这个values得到输出:一个<key,result> /** * map类 * @author xinxin * */ public static class DedepMap extends Mapper<Object, Text, Text, Text>{ private static Text line = new Text(); //实现map函数 public void map(Object key,Text value,Context context) { line=value; try { context.write(line, new Text("")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } /** * reduce 将输入的key复制到输出数据的key上并输出 * @author xinxin * */ public static class DeDupReduce extends Reducer<Text, Text, Text, Text>{ public void reduce(Text key,Iterable<Text> values,Context context) throws IOException, InterruptedException{ context.write(key, new Text("")); } } public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException { Configuration configuration= new Configuration(); String[] otherArgs = new GenericOptionsParser(configuration,args).getRemainingArgs(); if (otherArgs.length !=2) { System.err.println("Usage: Deduplication <in> <out>"); System.exit(2); } Job job =new Job(configuration, "tracert Deduplication");//新建一个job,给它起个名字,以便跟踪察看任务的执行情况--都有 job.setJarByClass(Deduplication.class);//主类---都有 //设置需要使用的map,combiner,reducer类 job.setMapperClass(DedepMap.class); job.setCombinerClass(DeDupReduce.class); job.setReducerClass(DeDupReduce.class); //设置map reduce 的输出健和输出值类型 job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); //设置文件输入类型和文件输出类型 FileInputFormat.addInputPath(job, new Path(otherArgs[0])); FileOutputFormat.setOutputPath(job, new Path(otherArgs[1])); System.exit(job.waitForCompletion(true)? 0 : 1); } }
相关文章推荐
- Linux环境下Navicat 11无限制使用的办法
- WF4.0 基础篇 (二十八) WF调用PowerShell
- WF4.0 基础篇 (二十六) Interop调用WF3.X的Activity
- Linux下/etc/skel框架目录的简介与使用
- 有关import sun.audio.AudioPlayer(或者其它文件)的问题
- WF4.0 基础篇 (十五) TransactionScope 事物容器
- linux gcc 编译时头文件和库文件搜索路径
- linux bash_profile和.bashrc区别
- Linux命令(3)
- Linux命令行下编辑常用的快捷键
- uva10271 - Chopsticks
- 强力推荐Linux下的五大BT下载工具
- Tomcat漏洞利用
- 常用的vim的option
- linux 输入子系统(3)----事件处理(input_handler层)
- linux下的静态库和动态库的编译
- opencv学习心得九----求轮廓的面积和周长
- opencv学习心得八----提取轮廓的点坐标
- 常见web中间件拿shell
- Linux 内核中的种种(初步了解2)