hello wordcount for hadoop
来源:互联网 发布:子域名挖掘机 编辑:程序博客网 时间:2024/06/06 09:21
package org.jediael.hadoopdemo.toolrunnerdemo;import java.io.IOException;import java.util.StringTokenizer;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.conf.Configured;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.IntWritable;import org.apache.hadoop.io.LongWritable;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;import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;import org.apache.hadoop.util.Tool;import org.apache.hadoop.util.ToolRunner;public class WordCount extends Configured implements Tool{public static class WordCountMap extendsMapper<LongWritable, Text, Text, IntWritable> {private final IntWritable one = new IntWritable(1);private Text word = new Text();public void map(LongWritable key, Text value, Context context)throws IOException, InterruptedException {String line = value.toString();StringTokenizer token = new StringTokenizer(line);while (token.hasMoreTokens()) {word.set(token.nextToken());context.write(word, one);}}}public static class WordCountReduce extendsReducer<Text, IntWritable, Text, IntWritable> {public void reduce(Text key, Iterable<IntWritable> values,Context context) throws IOException, InterruptedException {int sum = 0;for (IntWritable val : values) {sum += val.get();}context.write(key, new IntWritable(sum));}}@Overridepublic int run(String[] args) throws Exception {Configuration conf = new Configuration();Job job = new Job(conf);job.setJarByClass(WordCount.class);job.setJobName("wordcount");job.setOutputKeyClass(Text.class);job.setOutputValueClass(IntWritable.class);job.setMapperClass(WordCountMap.class);job.setReducerClass(WordCountReduce.class);job.setInputFormatClass(TextInputFormat.class);job.setOutputFormatClass(TextOutputFormat.class);FileInputFormat.addInputPath(job, new Path(args[0]));FileOutputFormat.setOutputPath(job, new Path(args[1]));return(job.waitForCompletion(true)?0:-1);}public static void main(String[] args) throws Exception {int exitCode = ToolRunner.run(new WordCount(), args);System.exit(exitCode);}}
参考:http://blog.csdn.net/jediael_lu/article/details/38751885
0 0
- hello wordcount for hadoop
- hadoop之"hello world"--wordCount
- Hadoop的“Hello world”---WordCount
- Hadoop中的Hello Word程序WordCount
- hadoop实实的体验--hello -wordcount
- hadoop mapreduce hello world(wordcount)
- Hadoop之道--MapReduce之Hello World实例wordcount
- Hadoop之道--MapReduce之Hello World实例wordcount
- hadoop wordcount
- hadoop wordcount
- hadoop-wordcount
- Hadoop WordCount
- hadoop-wordcount
- hadoop wordcount
- <hadoop>hadoop wordcount
- hadoop 运行 wordcount
- hadoop wordcount运行实例
- hadoop wordcount源代码分析
- android:TableLayout 布局详解
- CDHtmlDialog 小结(日文)
- 初见ubunt 为root设置密码
- 防止ViewPager中的Fragment被销毁的方法,更加流畅
- 制作WindowsServer2003SP2EnterpriseEdition U盘引导安装盘
- hello wordcount for hadoop
- 根据光标位置进行画出连续的点
- zlib-1.2.8 mips 平台交叉编译
- VS2010源代码与原始版本不同的解决办法
- cisco路由器&三层交换机简单环境配置实例
- ios自定义瀑布流控件
- Foundation框架中的其它常用细节
- 微信公众平台开发(76) 无高级接口账号获取用户基本信息
- first