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 org.hadoop.hadoop.conf.conf.conf. org.apache.hadoop.fs.path ؛ import org.apache.hadoop.io.intwritable ؛ import org.apache.hadoop.io.longwritable ؛ import org.apache.hadoop.io.tex org.apache.hadoop.mapreduce.mapper.context ؛ استيراد org.apache.hadoop.mapreduce.reducer ؛ استيراد org.apache.hadoop.mapreduce.lib.input.fileInputformat ؛ استيراد org.apache.hadoop.mapreduce.lib.output.fileutformat ؛ org.apache.hadoop.util.tool ؛ استيراد org.apache.hadoop.util.toolrunner ؛ استيراد org.jboss.netty.util.internal.stringutil ؛ فئة الطبقة العامة provincountmapredude يمتد الأدوات المكوّنة mapper <longwritable ، نص ، مقصود ، لا يمكن أن يكون مقصودًا> {private intwrity mapoutputkey = new intwritable () ؛ private contrable mapoutputvalue = new confulable (1) ؛@overridepublic void map (مفتاح طويل ، قيمة نصية ، سياق السياق) يلقي ioexception ، interruptedexception {//get get linevalue = value.toString () ؛ // splitsstring [] strs = 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 ؛ حاول {provinceId = integer.valueof (provinceIdValue) ؛} catch (استثناء e) {return ؛} if (provinceid == integer.max_value) {return ؛} mapoutkey.set (provincid) ؛ commout.write (maputputekey ، mapoutputValue) ؛}} // 2.Reducepublic static class wordCountReduce يمتد المخفضات <intrable ، مقصودة ، مقصودة ، لا يمكن أن يكون مقصودًا> {private dity outputvalue = new intwitable () 0 ؛ من أجل (القيمة المنقولة: القيم) {sum += value.get () ؛} outputvalue.set (sum) ؛ context.write (key ، outputvalue) ؛}} public int int (string [] args) reases {// 1.get configmonfiguration conf = super.getConf () ؛ this.getClass (). getSimplename ()) ؛ Job.setJarByClass (processecountmapreduce.class) ؛ // mapperjob.setmapperClass (WordCountMapper.class) ؛ Job.setMapOutputKeyClass (contrable.class) ؛ job.setMapOutputValueClass (contrable.class) ؛ // 3.3 مجموعة LEMBERJOB.SETREDREDUCERCLASS ( = Job.WaitforCompletion (true) ؛ إرجاع issuccess؟ 0: 1 ؛} الفراغ الثابت العام (سلسلة [] args) يلقي الاستثناء {args = جديد String [] {"HDFS: //hadoop-senior02.beifeng.com: 8020/input/2015082818" ، "HDFS: //hadoop-senior02.beifeng.com: 8020/output15/"} ؛ configuration conf = new configuration () ؛ الحالة = toolrunner.run (conf ، New ProvincecountMapReduce () ، args) ؛ system.exit (status) ؛}} 3. نتائج التشغيل
1) رمز التشغيل: bin/hdfs dfs -txt/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 الذي قدمه لك المحرر. آمل أن يكون ذلك مفيدًا لك. هنا ، يشكر المحرر أيضًا الجميع على دعمهم لموقع Wulin Network!