/**
*
*/
/**
* @author hadoop
*
*/
package MapReduce;
import java.io.IOException;
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.io.Writable;
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;
//o
public class WordCount {
public static void main(String[] args) throws Exception {
Configuration conf=new Configuration();//wordcounter zong guanjia=>job
Job job = Job.getInstance(conf);
job.setMapperClass(MyMapper.class);
job.setReducerClass(MyReducer.class);
job.setJarByClass(WordCount.class);
//map input default,not need to set,so just set output
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class);
//reduce:map's output is reduce's input,so just set reduce;s output
//reduce's output is the final output
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
//set data source and where to put
FileInputFormat.setInputPaths(job, new Path("hdfs://localhost:9000/new/WordCount.txt"));//represent hdfs root content,after "/source.txt",source exists
FileOutputFormat.setOutputPath(job, new Path("hdfs://localhost:9000/output.txt"));//output where,after"/",book.txt,book can be not exist
job.waitForCompletion(true);//start
}
}
class MyMapper extends Mapper<Object,Text,Text,IntWritable>{
//mapper-alt+/-oracle.apache.hadoop.mapreduce related class-<KEYIN,VALUEIN,KEYOUT,VALUEOUT>
//alt+/-double click"map"-delete a little:
protected void map(Object key,Text value,Context context)throws IOException,InterruptedException{
//the variable is because the before we set
//turn text to String,which backs String
String line=value.toString();
String[] words=line.split(" ");//back to String num group
for(int i=0;i<words.length;i++) {//there are lots of String,so we one to one
//cuz our output is text,so turn it into String
Text word=new Text(words[i]);
//next we ouput the number 1,Intwritable
IntWritable one=new IntWritable(1);//this value always =1 to any word
context.write(word,one);
}//for
}//protected
}//class map
//<hello,1><hello,1> =>guibing <hello,<1,1,1,1,1,1> >
class MyReducer extends Reducer<Text,Writable,Text,Writable>{
//r-reduce method-double clicks
//and we leave:
protected void reduce(Text keyIn,Iterable<IntWritable> valueIn,Context context)throws IOException,InterruptedException{
//Iterable rongqi,it is used to put like<1,1,1,1,1,1,1>
//so next we need to count the <1,1,1,1,1,1,1>
int sum=0;
//zeng qiang de for
for(IntWritable n : valueIn) {
sum+=n.get();
}//for
IntWritable result=new IntWritable(sum);
context.write(keyIn,result);
}//protected
}//class reduce
没有合适的资源?快使用搜索试试~ 我知道了~
MapReduce WordCount
需积分: 0 0 下载量 86 浏览量
2024-05-14
16:11:31
上传
评论
收藏 56.92MB GZ 举报
温馨提示
共128个文件
jar:121个
class:3个
project:1个
MapReduce WordCount
资源推荐
资源详情
资源评论
收起资源包目录
MapReduce WordCount (128个子文件)
MyMapper.class 2KB
MyReducer.class 2KB
WordCount.class 2KB
.classpath 8KB
aws-java-sdk-1.7.4.jar 11.39MB
hadoop-hdfs-2.7.1.jar 7.86MB
hadoop-common-2.7.1.jar 3.27MB
hadoop-yarn-api-2.7.1.jar 1.92MB
netty-all-4.0.23.Final.jar 1.7MB
hadoop-yarn-common-2.7.1.jar 1.58MB
guava-11.0.2.jar 1.57MB
commons-math3-3.1.1.jar 1.53MB
hadoop-mapreduce-client-jobclient-2.7.1-tests.jar 1.46MB
hadoop-mapreduce-client-core-2.7.1.jar 1.46MB
htrace-core-3.1.0-incubating.jar 1.41MB
mockito-all-1.8.5.jar 1.35MB
hadoop-yarn-server-resourcemanager-2.7.1.jar 1.18MB
xercesImpl-2.9.1.jar 1.17MB
netty-3.6.2.Final.jar 1.14MB
leveldbjni-all-1.8.jar 1021KB
snappy-java-1.0.4.1.jar 973KB
jaxb-impl-2.2.3-1.jar 869KB
jackson-databind-2.2.3.jar 846KB
zookeeper-3.4.6.jar 774KB
jackson-mapper-asl-1.9.13.jar 762KB
hadoop-mapreduce-client-common-2.7.1.jar 734KB
jersey-server-1.9.jar 696KB
guice-3.0.jar 694KB
apacheds-kerberos-codec-2.0.0-M15.jar 675KB
hadoop-yarn-server-nodemanager-2.7.1.jar 672KB
azure-storage-2.0.0.jar 647KB
joda-time-2.8.1.jar 607KB
commons-collections-3.2.1.jar 562KB
jetty-6.1.26.jar 527KB
jets3t-0.9.0.jar 527KB
zookeeper-3.4.6-tests.jar 527KB
protobuf-java-2.5.0.jar 521KB
hadoop-mapreduce-client-app-2.7.1.jar 501KB
log4j-1.2.17.jar 478KB
jersey-core-1.9.jar 448KB
httpclient-4.2.5.jar 423KB
commons-lang3-3.3.2.jar 403KB
hadoop-yarn-server-common-2.7.1.jar 353KB
commons-httpclient-3.1.jar 298KB
avro-1.7.4.jar 296KB
commons-configuration-1.6.jar 292KB
commons-lang-2.6.jar 278KB
hadoop-rumen-2.7.1.jar 275KB
hadoop-mapreduce-examples-2.7.1.jar 267KB
commons-net-3.1.jar 267KB
curator-recipes-2.7.1.jar 264KB
junit-4.11.jar 239KB
commons-compress-1.4.1.jar 236KB
jackson-core-asl-1.9.13.jar 227KB
httpcore-4.2.5.jar 222KB
hadoop-gridmix-2.7.1.jar 213KB
commons-beanutils-core-1.8.0.jar 201KB
hadoop-yarn-server-applicationhistoryservice-2.7.1.jar 193KB
xml-apis-1.3.04.jar 190KB
jackson-core-2.2.3.jar 188KB
gson-2.2.4.jar 186KB
commons-beanutils-1.7.0.jar 184KB
curator-framework-2.7.1.jar 182KB
jsch-0.1.42.jar 181KB
commons-io-2.4.jar 181KB
jetty-util-6.1.26.jar 173KB
hadoop-mapreduce-client-hs-2.7.1.jar 160KB
hadoop-nfs-2.7.1.jar 156KB
jersey-json-1.9.jar 144KB
commons-digester-1.8.jar 140KB
hadoop-yarn-client-2.7.1.jar 139KB
hadoop-azure-2.7.1.jar 131KB
jersey-client-1.9.jar 127KB
hadoop-sls-2.7.1.jar 112KB
hadoop-openstack-2.7.1.jar 112KB
hadoop-streaming-2.7.1.jar 103KB
jaxb-api-2.2.2.jar 103KB
servlet-api-2.5.jar 103KB
hadoop-aws-2.7.1.jar 101KB
hadoop-distcp-2.7.1.jar 100KB
hadoop-hdfs-nfs-2.7.1.jar 100KB
jsp-api-2.1.jar 98KB
hadoop-yarn-registry-2.7.1.jar 95KB
xz-1.0.jar 92KB
metrics-core-3.0.1.jar 83KB
api-util-1.0.0-M20.jar 78KB
hadoop-auth-2.7.1.jar 69KB
curator-client-2.7.1.jar 68KB
jettison-1.1.jar 66KB
guice-servlet-3.0.jar 63KB
hadoop-extras-2.7.1.jar 63KB
activation-1.1.jar 62KB
commons-logging-1.1.3.jar 61KB
commons-codec-1.4.jar 57KB
hadoop-yarn-server-sharedcachemanager-2.7.1.jar 52KB
hadoop-yarn-applications-distributedshell-2.7.1.jar 45KB
hamcrest-core-1.3.jar 44KB
apacheds-i18n-2.0.0-M15.jar 44KB
hadoop-mapreduce-client-shuffle-2.7.1.jar 44KB
asm-3.2.jar 42KB
共 128 条
- 1
- 2
资源评论
我一个爆哭啊
- 粉丝: 7
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于Java的本科探索学习项目设计源码 - 本科探索
- 基于Javascript和Python的微商城项目设计源码 - MicroMall
- 基于Java的网上订餐系统设计源码 - online ordering system
- 基于Javascript的超级美眉网络资源管理应用模块设计源码
- 基于Typescript和PHP的编程知识储备库设计源码 - study-php
- Screenshot_2024-05-28-11-40-58-177_com.tencent.mm.jpg
- 基于Dart的Flutter小提琴调音器APP设计源码 - violinhelper
- 基于JavaScript和CSS的随寻订购网页设计源码 - web-order
- 基于MATLAB的声纹识别系统设计源码 - VoiceprintRecognition
- 基于Java的微服务插件集合设计源码 - wsy-plugins
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功