博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Hadoop案例数据去重
阅读量:7222 次
发布时间:2019-06-29

本文共 2008 字,大约阅读时间需要 6 分钟。

hot3.png

import java.io.IOException;
import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.IntWritable;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 QuChong { /**  * 数据去重 利用并化的的思想  * @author hadoop  *  */ public static class Engine extends Mapper
{      public void map(Object key, Text value, Context context) throws IOException, InterruptedException {      String line = value.toString();      context.write(new Text(line), new Text(""));     }   }      public static class IntSumReducer extends Reducer
 {         public void reduce(Text key, Iterable
 values, Context context) throws IOException, InterruptedException {     context.write(key, new Text(""));     }   }
   public static void main(String[] args) throws Exception {  //设置引擎配置类,包括引擎地址,引擎输入输出参数(目录)     Configuration conf = new Configuration();     String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();     if (otherArgs.length != 2) {       System.err.println("Usage: wordcount 
 
");       System.exit(2);     }     Job job = new Job(conf, "word count");     job.setJarByClass(QuChong.class);     //设置Map、Combine和Reduce处理类     job.setMapperClass(Engine.class);     job.setCombinerClass(IntSumReducer.class);     job.setReducerClass(IntSumReducer.class);     //设置输出类     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);   }}

转载于:https://my.oschina.net/u/1169079/blog/201872

你可能感兴趣的文章
中国大学MOOC —— 学习笔记(四)
查看>>
访问,ringbtn,
查看>>
致橡树
查看>>
一段测试代码,哦哦哦,
查看>>
uiimagepickercontroller,中文,--》摘
查看>>
第四次作业
查看>>
在python中调用js或者nodejs
查看>>
【年终总结】2年计划还是要有的,万一实现了呢?(转自叶小钗)
查看>>
数字图像处理学习笔记(1.1)---位图的读写、几何变换、傅里叶变换、直方图均衡...
查看>>
javascript数组顺序-----1冒泡的另一种比较好理解的写法
查看>>
数据结构-栈的实现之行编译器核心实现
查看>>
C++ Project 积累(2)
查看>>
(1)用VisualSvn Server,Tortoise Svn,AnkhSvn搭建Svn版本控制
查看>>
Mysql索引
查看>>
格式化输出
查看>>
hdu 3804 Query on a tree (树链剖分+线段树)
查看>>
定位、指南针、地理编码
查看>>
Kafka 简介
查看>>
MySQL 用户连接与用户线程
查看>>
RabbitMq、ActiveMq、Kafka和Redis做Mq对比
查看>>