0

0

Hadoop2.0 YARN cloudra4.4.0 WordCount实例

php中文网

php中文网

发布时间:2016-06-07 15:15:29

|

1650人浏览过

|

来源于php中文网

原创

其他都没啥 这个 jar都在这里了。 import java.io.IOException;import java.util.StringTokenizer;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.IntWritable;import org.apache.hadoop.io.Te

Hadoop2.0 YARN cloudra4.4.0 WordCount实例 

其他都没啥 这个 jar都在这里了。

import java.io.IOException;
import java.util.StringTokenizer;

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 WordCount {

  public static class TokenizerMapper 
       extends Mapper{
    
    private final static IntWritable one = new IntWritable(1);
    private Text word = new Text();
      
    public void map(Object key, Text value, Context context
                    ) throws IOException, InterruptedException {
      StringTokenizer itr = new StringTokenizer(value.toString());
      while (itr.hasMoreTokens()) {
        word.set(itr.nextToken());
        context.write(word, one);
      }
    }
  }
  
  public static class IntSumReducer 
       extends Reducer {
    private IntWritable result = new IntWritable();

    public void reduce(Text key, Iterable values, 
                       Context context
                       ) throws IOException, InterruptedException {
      int sum = 0;
      for (IntWritable val : values) {
        sum += val.get();
      }
      result.set(sum);
      context.write(key, result);
    }
  }

  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(WordCount.class);
    job.setMapperClass(TokenizerMapper.class);
    job.setCombinerClass(IntSumReducer.class);
    job.setReducerClass(IntSumReducer.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);
    FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
    FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
    System.exit(job.waitForCompletion(true) ? 0 : 1);
  }
}

导出为Jar包,上传(发现这个版本居然不知道怎么在Eclipse里直接跑,只好上传了)

Hadoop2.0 YARN cloudra4.4.0 WordCount实例

./hadoop  jar ../etc/hadoop/WordCount.jar /user/hadoop/input /user/hadoop/output

input里是yard02的etc/profile文件

结果:

!=	1
"$BASH"	2
"$PS1"	1
"/bin/sh"	1
"`id	1
#	6
$i	2
&&	1
'	3
(bash(1),	1
(sh(1))	1
-d	1
-eq	1
-f	1
-r	1
-u`"	1
.	2
...).	1
.profile	1
/etc/bash.bashrc	2
/etc/login.defs.	1
/etc/profile.d	1
/etc/profile.d/*.sh;	1
/etc/profile:	1
0	1
Bourne	2
CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH	1
JAVA_HOME=/usr/local/jdk1.7.0_21	1
JRE_HOME=/usr/local/jdk1.7.0_21/jre	1
PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH	1
PS1.	1
PS1='#	1
PS1='$	1
PS1='\h:\w\$	1
See	1
The	2
[	7
]	1
];	6
already	1
and	2
ash(1),	1
bash.bashrc	1
by	1
compatible	1
default	2
do	1
done	1
else	2
export	4
fi	6
file	2
for	2
handled	1
i	2
if	6
in	1
is	1
ksh(1),	1
now	1
pam_umask(8)	1
pam_umask.	1
sets	1
shell	1
shells	1
system-wide	1
the	2
then	6
umask	1
unset	1


WPS零基础入门到精通全套教程!
WPS零基础入门到精通全套教程!

全网最新最细最实用WPS零基础入门到精通全套教程!带你真正掌握WPS办公! 内含Excel基础操作、函数设计、数据透视表等

下载

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

相关专题

更多
漫蛙2入口地址合集
漫蛙2入口地址合集

本专题整合了漫蛙2入口汇总,阅读专题下面的文章了解更多详细内容。

163

2026.01.06

AO3中文版地址汇总
AO3中文版地址汇总

本专题整合了AO3中文版地址合集,阅读专题下面的文章了解更多详细内容。

88

2026.01.06

python cv2模块教程大全
python cv2模块教程大全

本专题整合了python cv2模块相关教程,阅读专题下面的文章了解更多详细教程。

42

2026.01.06

python创建txt文件教程大全
python创建txt文件教程大全

本专题整合了python创建txt文件相关教程,阅读专题下面的文章了解更多详细内容。

21

2026.01.06

python去掉字符串空格教程大全
python去掉字符串空格教程大全

本专题整合了python去掉字符串空格教程大全,阅读专题下面的文章了解更多详细内容。

2

2026.01.06

Python /与// 教程大全
Python /与// 教程大全

本专题整合了python的/和//的相关内容大全,阅读下面的文章了解更多详细内容。

23

2026.01.06

Python /与// 教程大全
Python /与// 教程大全

本专题整合了python的/和//的相关内容大全,阅读下面的文章了解更多详细内容。

0

2026.01.06

Python /与// 教程大全
Python /与// 教程大全

本专题整合了python的/和//的相关内容大全,阅读下面的文章了解更多详细内容。

0

2026.01.06

python func函数合集
python func函数合集

本专题整合了python func函数相关教程,阅读专题下面的文章了解更多详细内容。

0

2026.01.06

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
NPM包管理工具精讲课程
NPM包管理工具精讲课程

共8课时 | 0.9万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号