需求:
统计页面浏览量(每行记录就是一次浏览)
思路:
只需要把每一行的数据设置为相同的key
开发步骤:
Map:
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
context.write(new Text("line"), new IntWritable(1));
}
Reduce:
protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
int sum = 0;
for (IntWritable val : values) {
sum += val.get();
}
result.set(sum);
context.write(key, result);
}