1。要件
ログログに記載されている情報については、ウェブサイトのさまざまな州のユーザーへの訪問数を数えます。
2。プログラミングコード
Package org.apache.hadoop.studyhdfs.mapreduce; Import java.io.ioexception; Import org.apache.commons.lang.stringutils; Import org.apache.hadoop.conf.configuration; Import org.apache.hadoop.conf.configuration; import.apach.hadoop.conf.conf.conf.conf.conf.configuration; apache.hadoop.fs.path; Import org.apache.hadoop.io.intwritablot; Import org.apache.hadoop.io.longwritaTh; import org.apache.hadoop.io.text; import org.apache.hadoop.mapreduce.job; Import org.apache.hadoop.mapreduce.mapper; apache.hadoop.mapreduce.mapper.context; import org.apache.hadoop.mapreduce.deducer; import org.apache.hadoop.mapreduce.lib.input.fileinputformat; Import org.apache.hadoop.mapreduce.lib.outtuptutputpontot; org.apache.hadoop.util.tool; Import org.apache.hadoop.util.toolrunner; Import org.jboss.netty.util.internal.stringutil; public class genuncecountmapreduce拡張設定された実装ツール{//1.map/** mapper <longwritable、text、intwritable、intwritable> {private intwritable mapoutputkey = new intwritable(); private intwritable mapoutputvalue = new intwrita(1);@overriditableキー、テキスト値、コンテキスト)スローIOException、cutrdedexception {// strs = lieneValue.split( "/t"); // line blankstring url = strs [1]; string provenceidvalue = strs [23]; // guolvif(strs.length <30 || stringutils.isblank(provenceidvalue)|| stringutils.isblank(url)){return; } int provenceid = integer.max_value; try {provenceid = integer.valueof(provenceidvalue);} catch(exception e){return;} if(provenceid == integer.max_value){return;} mapoutputkey.set(クラスwordcountreduceはreducter <intwritable、intwritable、intwritable、intwritable> {private intwritable outputvalue = new intwritable();@overridepublic void reduce(intwritable <intwrita> values、values、context context)throws ioexception、interpededexception {// += value.get();} outputValue.set(sum); context.write(key、outputValue);}} public int run(string [] args)shrows {// 1.get configurationconfiguration conf = super.getConf(); // 2.create jobjob job = job.getinstance(conf、conf、conf、 this.getClass()。getsimplename()); job.setjarbyclass(provincecountmapreduce.class); // 3. set job // 3.1 set inputpath inputpath = new path(args [0]); fileinputformat.addinputpath(job、inputpath); // 3.2 Set set set set mapperjob.setmapperclass(wordcountmapper.class); job.setmapoutputkeyclass(intwritable.class); job.setmapoutputvalueclass(intwritable.class); // 3.3 set ReduceJob.setReducerClass(wordcountreduce.class); job.setOutputkeyclass(intwritable.class); job.setOutputValueClass(intwritable.class); // 3.4 Set inputpath outputpath = new Path(args [1]); fileoutputformat.setutputput(outtuptath); outtutpath); = job.waitforcompletion(true); return issuccess?0:1;} public static void main(string [] args)throws exception {args = new string [] {"hdfs://hadoop-senior02.beifeng.com:8020/input/2015082818"、 "hdfs://hadoop-senior02.beifeng.com:8020/output15/"}; configuration conf = new configuration(); conf.set( "mapredc.tut.tupt.tups.tups.tut.tupt.tut.tut.tupt.tupt.tupt.tupt. status = toolrunner.run(conf、new provincecountmapreduce()、args); system.exit(status);}}}} 3。操作結果
1)実行コードの実行:bin/hdfs dfs -text/output15/par*
2)操作結果:
1 3527
2 1672
3 511
4 325
5 776
6 661
7 95
8 80
9 183
10 93
11 135
12 289
13 264
14 374
15 163
16 419
17 306
18 272
19 226
20 2861
21 124
22 38
23 96
24 100
25 20
26 157
27 49
28 21
29 85
30 42
32 173
上記は、編集者が紹介したJava Code Statistics Webサイトのさまざまな州でのユーザーの訪問数への関連する紹介です。それがあなたに役立つことを願っています。ここでは、編集者はWulin Network Webサイトのサポートにも感謝します!