1. 요구 사항
로그 로그에 제공된 정보의 경우 웹 사이트의 다른 지방의 사용자 방문 수를 계산하십시오.
2. 프로그래밍 코드
package org.apache.hadoop.studyhdfs.mapreduce; import java.io.ioexcept; import org.apache.commons.lang.stringutils; import org.apache.hadoop.conf.configuration; import org.apache.hadoop.conf.configuration; import org.apache.hadoop.conf.confured; 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.mapreduce.mapreduce.mapporp; org.apache.hadoop.mapreduce.mapper.context; import org.apache.hadoop.mapreduce.regnucer; import org.apache.hadoop.mapreduce.input.fileinputformat; import org.apache.hadoop.mapreduce.lib.outpolut.fileoutformat; hadopache org.apache.hadoop.util.toolrunner; import org.jboss.netty.util.internal.stringutil; public class provincecountmapreduce 확장 구성 도구 {//1.map/** <keyin, valuein, keyout, valueout>*/public static class mapper elpper, 텍스트, intwritation, intwrittine intwritable mapoutputkey = new intwritable (); private intwithity mapoutputvalue = new intwlitable (1);@atriadepublic void map (longwarity key, 텍스트 값, 컨텍스트 컨텍스트) Ioexception, InterruptedException {// linevaluestring linevalue = value.tostring (); = lineValue.split ( "/t"); // line blankstring url = strs [1]; String ProvinceIdValue = strs [23]; // guolvif (strs.length <30 || StringUtils.isblank (ProvinceIdValue) || StringUtils.isblank (url)) {return; } int provinceid = integer.max_value; try {provinceId = integer.valueof (provinceIdValue);} catch (예외 e) {return;} if (provinceId == integer.max_value) {return;} mapoutputkey.set (context.write); mapoutputkey, mapOutputValue);}} // 2.reducepublic static class wordCountreDuce는 retward <intwritable, intwritable, intwritable> {private intwritable outWritable = new Intwritable ();@revidepublic void reture (intwratable reeditable, 컨텍스트)를 확장합니다. sum = 0; for (intwritable value : value) {sum += value.get ();} outputValue.set (sum); context.write (key, outputValue);}} public int run (string [] args) 예외 {// 1. 1. 구성 configuration conf.getconf (2.create jobjob) this.getClass (). getSimplename ()); job.setJarbyClass (provinccountMapreduce.class); // 3. 3.1 세트 작업 // 3.1 SET INPUTPATH INPUTPATH = NEW PATH (args [0]); FileInputFormat.AddInputPath (job, inputpath); // 3.2 SET. mapperjob.setMapperClass (wordCountMapper.class); job.setMapoutPutKeyClass (intWritable.class); job.setMapoutPutValueClass (intwritable.class); // 3.3 세트 ReduceJob.setReducerClass (wordCountreDuce.class); job.setOutputKeyClass (intwritable.class); job.setOutputValueClass (intwritable.class); // 3.4 set inputpath outpath = new Path (Args [1]); fileOutputFormat.setOutPut (job, outputputes); // 4.SUBLOUNBOOLEAN INSUCCESS = job.waitforCompletion (true); 반환 IsSuccess? 0 : 1;} public static void main (String [] args)은 예외 {args = new 문자열 [] { "hdfs : //hadoop-senior02.beifeng.com : 8020/input/2015082818", "hdfs : //hadoop-senior02.beifeng.com : 8020/output15/"}; configuration conf = new configuration (); "mapreduce.map.output.output" status = ToolRunner.run (conf, New ProvincountMapreduce (), args); System.Exit (상태);}} 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 웹 사이트에서 다른 지방의 사용자 방문 수에 대한 관련 소개입니다. 나는 그것이 당신에게 도움이되기를 바랍니다. 여기에서 편집자는 Wulin Network 웹 사이트에 대한 지원에 감사드립니다!