import
java.io.IOException;
import
org.apache.hadoop.conf.Configuration;
import
org.apache.hadoop.fs.Path;
import
org.apache.hadoop.io.LongWritable;
import
org.apache.hadoop.io.NullWritable;
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;
public
class
wzl189_distinct {
public
static
class
MyMapper
extends
Mapper<Object, Text, Text, NullWritable> {
Text outKey =
new
Text();
@Override
public
void
map(Object key, Text value, Context context)
throws
IOException, InterruptedException {
String tmp[] = value.toString().split(
" "
);
if
(tmp.length !=
2
)
return
;
outKey.set(tmp[
0
]);
context.write(outKey, NullWritable.get());
}
}
public
static
class
MyReducer
extends
Reducer<Text, NullWritable, LongWritable, NullWritable> {
long
myCount = 0l;
@Override
public
void
reduce(Text key, Iterable<NullWritable> values,
Context context)
throws
IOException, InterruptedException {
++myCount;
}
@Override
public
void
cleanup(Context context)
throws
IOException,
InterruptedException {
context.write(
new
LongWritable(myCount), NullWritable.get());
};
}
public
static
void
main(String[] args)
throws
Exception {
Configuration conf =
new
Configuration();
if
(args.length !=
2
) {
System.err.println(
"Usage: <in> <out>"
);
System.exit(
2
);
}
conf.set(
"mapred.child.java.opts"
,
"-Xmx350m -Xmx1024m"
);
@SuppressWarnings
(
"deprecation"
)
Job job =
new
Job(conf,
"wzl189_distinct"
);
job.setNumReduceTasks(
1
);
job.setInputFormatClass(TextInputFormat.
class
);
job.setJarByClass(wzl189_distinct.
class
);
job.setMapperClass(MyMapper.
class
);
job.setMapOutputKeyClass(Text.
class
);
job.setMapOutputValueClass(NullWritable.
class
);
job.setReducerClass(MyReducer.
class
);
job.setOutputKeyClass(Text.
class
);
job.setOutputValueClass(NullWritable.
class
);
FileInputFormat.addInputPath(job,
new
Path(args[
0
]));
FileOutputFormat.setOutputPath(job,
new
Path(args[
1
]));
System.exit(job.waitForCompletion(
true
) ?
0
:
1
);
}
}
相关推荐
MapReduce操作实例-数据去重.pdf 学习资料 复习资料 教学资源
mapreduce实现文档数据去重
用MapReduce解决下面的问题,只是出个题而已
(一)编程实现文件合并和去重操作 对于两个输入文件,即文件 A 和文件 B,请编写 MapReduce 程序,对两个文件进行合并, 并剔除其中重复的内容,得到一个新的输出文件 C。下面是输入文件和输出文件的一个样例 供...
大数据Mapreduce(1)编程实现文件合并和去重操作.docx
mapreduce mapreduce mapreduce mapreduce mapreduce mapreduce mapreduce mapreduce mapreduce mapreduce mapreduce mapreduce mapreduce mapreduce mapreduce mapreduce mapreduce mapreduce mapreduce mapreduce ...
NULL 博文链接:https://zc985552943.iteye.com/blog/2088221
Jobtracker启动报错:解决方法:导入guava-r09-jarjar.jar org/apache/hadoop/thirdparty/guava/common/collect/LinkedListMultimap错误分析及解决方法: Intel版本hadoop因为缺少license,启动jobtracker报错:
(2)打开网站localhost:8088和localhost:50070,查看MapReduce任务启动情况 (3)写wordcount代码并把代码生成jar包 (4)运行命令 (1):把linus下的文件放到hdfs上 (2):运行MapReduce (5):查看运行结果 ...
(实践一)数值概要中combiner的作用 在前述数值概要的运用中,加入不同的combiner,测试不同环境下系统的性能,并给出分析、...(实践五)去重的用户—针对ctrip数据集去重 对ctrip数据集中的product-id进行去重操作
4 分别在自编 MapReduce 程序 WordCount 运行过程中和运行结束后查看 MapReduce Web 界面。 5. 分别在自编 MapReduce 程序 WordCount 运行过程中和运行结束后练习 MapReduce Shell 常用命令。 。。
Hadoop MapReduce作业卡死问题的解决方法.docx
核心框架是MapReduce,使用Java语言编写,在执行时传递args[0]和args[1]即可。可以根据图片转换的Base64编码的不同达到去除相同内容不同文件名图片的目的。 在识别指定目录(args[0])下的图片后将去重后的图片结果...
云计算技术之————MapReduce 详细介绍MapReduce
, 《MapReduce设计模式》是一本关于设计模式的书,为读者提供解决问题的模板或通用指南。书中主要介绍编程模式,即如何利用MapReduce框架解决一类问题,重在提供解决问题的方法和思路。作者花大量篇幅介绍各种模式的...
MapReduce2.0程序设计,包括编程模型介绍,编程接口介绍,Java编程与多语言编程的理论与实践
【MapReduce篇07】MapReduce之数据清洗ETL1
本节通过单词计数实例来阐述采用 MapReduce 解决实际问题的基本思路和具体实现过程。 设计思路 首先,检查单词计数是否可以使用 MapReduce 进行处理。因为在单词计数程序任务中,不同单词的出现次数之间不存在...
MapReduce发明人关于MapReduce的介绍
《MapReduce2.0源码分析与编程实战》强调理论联系实际,帮助读者在掌握MapReduce2.0基本知识和特性的基础上,培养实际编程和解决大数据处理相关问题的能力。《MapReduce2.0源码分析与编程实战》可作为学习MapReduce...