- 主页 > 生活百科 > >
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);
}
}
推荐阅读
-
戴尔笔记本电脑开机蓝屏怎么解决方法-戴尔笔记本老是蓝屏怎么解决-
-
亚欧非贸促会台州分部|中国国际服务贸易交易会工作组等给亚欧非贸促会发来感谢信!
-
-
短发|林青霞终于换发型!掀起刘海扎马尾辫更贵气,曾花10000元剪短发
-
青年|“我的世界就是垃圾”,这句话细细思考后,赞同该观点的人不少
-
[红餐]这个五谷茶饮品牌如何持续变革,开出1500+家门店后
-
-
肖战|肖战上《时尚芭莎》杂志封面!还是开年首刊,新剧却无缘12月播
-
-
进行|全国股转公司总经理徐明:全面深化新三板改革要尊重四个规律
-
巴菲特▲中国股市:最会赚钱的50家公司,谁会涨成“千倍股”?
-
豆丁妈妈育儿记|这份关于孩子的防暑降温指南送给你,建议收藏,今天夏至
-
企业|狭义货币(M1)增速创两年半新高 企业经营活跃度进一步提升
-
环球快资讯■已确诊5千余人,美国防工业遭沉重打击!美军每天新增100例
-
双鱼座|10月中旬,好运傍身,4属相吉星近身,财旺贵人旺,幸福进门
-
-
隔壁老黄影评|被社会道德绑架中翻车了,5天前:红了30多年的周润发
-
斯巴达克斯|《斯巴达克斯》制作商Starz电视台迷你剧,又是熟悉味道的历史剧
-
-