- 主页 > 生活百科 > >
package cn.mr.dedup;
import JAVA.io.IOException;
import org.Apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.MApper;
public class DedupMapper extends Mapper<LongWritable, Text, Text, NullWritable> {
private static Text field = new Text();
// <0,2018-3-3 c><11,2018-3-4 d>
@Override
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
field = value;
context.write(field, NullWritable.get());
}
// <2018-3-3 c,null> <2018-3-4 d,null>
}
package cn.mr.dedup;
import java.io.IOException;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
public class DedupReducer extends Reducer<Text, NullWritable, Text, NullWritable> {
// <2018-3-3 c,null> <2018-3-4 d,null><2018-3-4 d,null>
@Override
protected void reduce(Text key, Iterable<NullWritable> values, Context context)
【Hadoop数据去重】throws IOException, InterruptedException {
context.write(key, NullWritable.get());
}
}
package cn.mr.dedup;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
public class DedupRunner {
public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
Configuration conf = new Configuration();
Job job = Job.getInstance(conf);
job.setJarByClass(DedupRunner.class);
job.setMapperClass(DedupMapper.class);
job.setReducerClass(DedupReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(NullWritable.class);
FileInputFormat.setInputPaths(job, new Path("D:\Dedup\input"));
// 指定处理完成之后的结果所保存的位置
FileOutputFormat.setOutputPath(job, new Path("D:\Dedup\output"));
job.waitForCompletion(true);
}
}
推荐阅读
-
-
五代十国|能让太祖赵匡胤忌惮不已的南唐大将林仁肇,为何被李煜用毒酒害死
-
Intel|6年之后依旧卖不动 Intel终止开发3D实感技术
-
-
社保卡养老金可以在各个银行柜台取钱吗?这可能是最好的答案
-
海底探探|做好这几点很重要,网贷逾期了暂时还不上怎么办
-
-
亲爱的麻洋街|任嘉伦又一新剧开机?现场对女主太宠,看到熟悉的她,cp粉激动了
-
-
传媒一班|人美心善水亦诗:父亲娶新妻被骂为其发声,和后妈同单位展露才华
-
路上|沙宝亮救人是怎么回事?亮哥真是娱乐圈热心肠老大哥啊!
-
-
暗月杀车队|恢复正常通行。,[最新路况]天柱收费站入口解除交通管制
-
甜宠影视|俄罗斯赔本抢,公然明抢!乌克兰好不容易找到首个安-178客户
-
四川遂宁|四川遂宁警方通报:18岁男子行凶后到公安机关投案,已被刑拘
-
-
芒种风向标|“你们睡在这里是为了什么?不害怕睡着的时候掉下去吗?”哈哈哈
-
「我的第一部5G手机」5G时代需防范“网络刺客” 车联网或最先遭难
-
官媒打脸! 韩红遭实名举报私吞5亿善款,到底动了谁的“奶酪”?
-
澳大利亚|一位澳籍华裔遭“忠诚度”测试:敢不敢谴责中国?