一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服務(wù)器之家 - 編程語(yǔ)言 - JAVA教程 - Java代碼統(tǒng)計(jì)網(wǎng)站中不同省份用戶的訪問(wèn)數(shù)

Java代碼統(tǒng)計(jì)網(wǎng)站中不同省份用戶的訪問(wèn)數(shù)

2020-04-27 12:16dafei10086 JAVA教程

這篇文章主要介紹了Java代碼統(tǒng)計(jì)網(wǎng)站中不同省份用戶的訪問(wèn)數(shù) 的相關(guān)資料,非常具有參考借鑒價(jià)值,感興趣的朋友一起學(xué)習(xí)吧

一、需求

針對(duì)log日志中給定的信息,統(tǒng)計(jì)網(wǎng)站中不同省份用戶的訪問(wèn)數(shù)

二、編程代碼

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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.Configured;
import 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.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Mapper.Context;
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.Tool;
import org.apache.hadoop.util.ToolRunner;
import org.jboss.netty.util.internal.StringUtil;
public class ProvinceCountMapReduce extends Configured implements Tool {
//1.map
/*
* <KEYIN,VALUEIN,KEYOUT,VALUEOUT>
*/
public static class WordCountMapper extends Mapper<LongWritable,Text,IntWritable,IntWritable>{
private IntWritable mapOutputKey =new IntWritable();
private IntWritable mapOutputValue =new IntWritable(1);
@Override
public void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException {
//get lineValue
String lineValue =value.toString();
//split
String[] strs =lineValue.split("\t");
//line blank
String url=strs[1];
String provinceIdValue =strs[23];
//guolv
if(strs.length < 30 || StringUtils.isBlank(provinceIdValue) || StringUtils.isBlank(url)){
return;
}
int provinceId =Integer.MAX_VALUE;
try {
provinceId=Integer.valueOf(provinceIdValue);
} catch (Exception e) {
return;
}
if(provinceId == Integer.MAX_VALUE){
return;
}
mapOutputKey.set(provinceId);
context.write(mapOutputKey, mapOutputValue);
}
}
//2.reduce
public static class WordCountReduce extends Reducer<IntWritable,IntWritable,IntWritable,IntWritable>{
private IntWritable outputValue =new IntWritable();
@Override
public void reduce(IntWritable key, Iterable<IntWritable> values,Context context)
throws IOException, InterruptedException {
//to do
int sum = 0;
for(IntWritable value:values){
sum +=value.get();
}
outputValue.set(sum);
context.write(key, outputValue);
}
}
public int run(String[] args) throws Exception{
//1.get Configuration
Configuration conf =super.getConf();
//2.create job
Job job =Job.getInstance(conf, this.getClass().getSimpleName());
job.setJarByClass(ProvinceCountMapReduce.class);
//3.set job
//3.1 set input
Path inputPath =new Path(args[0]);
FileInputFormat.addInputPath(job, inputPath);
//3.2 set mapper
job.setMapperClass(WordCountMapper.class);
job.setMapOutputKeyClass(IntWritable.class);
job.setMapOutputValueClass(IntWritable.class);
//3.3 set reduce
job.setReducerClass(WordCountReduce.class);
job.setOutputKeyClass(IntWritable.class);
job.setOutputValueClass(IntWritable.class);
//3.4 set input
Path outputPath =new Path(args[1]);
FileOutputFormat.setOutputPath(job, outputPath);
//4.submmit
boolean isSuccess =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("mapreduce.map.output.compress", "true");
int status=ToolRunner.run(conf, new ProvinceCountMapReduce() , args);
System.exit(status);
}
}

3、運(yùn)行結(jié)果

1)運(yùn)行代碼:bin/hdfs dfs -text /output15/par*

2)運(yùn)行結(jié)果:

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代碼統(tǒng)計(jì)網(wǎng)站中不同省份用戶的訪問(wèn)數(shù)的相關(guān)介紹,希望對(duì)大家有所幫助,在此小編也非常感謝大家對(duì)服務(wù)器之家網(wǎng)站的支持!

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产伦精品一区二区三区免 | 92国产福利久久青青草原 | 高清一区高清二区视频 | 国产精品免费_区二区三区观看 | 好涨好爽好大视频免费 | 亚洲va久久久久综合 | 亚洲天堂男人天堂 | 暖暖高清日本在线 | 欧美日韩中文字幕久久伊人 | 91精品国产麻豆国产自产在线 | 国产大秀视频一区二区三区 | 毛片a区| 亚洲欧美精品一区天堂久久 | 日本免费一区二区三区四区五六区 | 国产精品国语自产拍在线观看 | 大胸美女被c | 国产成人精品一区二区仙踪林 | x8x8国产在线观看2021 | 四虎免费看片 | 无限时间看片在线观看 | 午夜私人福利影院 | 白丝校花掀起短裙呻吟小说 | 色哟约 | 免费一级片在线 | 久久精品久久久 | 午夜无码国产理论在线 | 18捆绑调教在线高清 | 免费一区视频 | 国产在线精品成人一区二区三区 | 万域之王动漫在线观看全集免费播放 | 欧美交换乱理伦片120秒 | 精品国产免费观看一区高清 | 国产精品欧美亚洲韩国日本99 | 国产青草视频在线观看免费影院 | 日本一区二区三区在线 观看网站 | 国产成人精品实拍在线 | 成人精品亚洲人成在线 | 国内精品中文字幕 | 欧美日韩精品在线观看 | 国产午夜精品一区二区三区 | 欧美色青 |