介绍
这篇博客是关于如何在Hadoop MapReduce中进行Uber数据分析的。
数据
数据展示
数据说明
该数据有4列:
- dispatching_base_number
- date
- active_vehicles
- trips
问题描述
计算每个Basement每个周几总共有多少trips
MapReduce实现
Mapper
在Mapper中 使用java.time.LocalDate
来获取每个年月日具体是星期几,并将Basement_number+dayofweek
作为keys,tripNum
作为value。
1 | public static class ExtractTripMapper extends Mapper<Object, Text, Text, IntWritable> |
Combiner&Reducer
之后就与WordCont相同,进行简单的统计和合并。1
2
3
4
5
6
7
8
9
10
11
12
13public static class SumReducer extends Reducer<Text, IntWritable, Text, IntWritable>
{
public void reduce(Text key, Iterable<IntWritable> values, Context context)
throws IOException, InterruptedException
{
int sum = 0;
for (IntWritable val : values)
{
sum += val.get();
}
context.write(key, new IntWritable(sum));
}
}