自行车数据"/>
MapReduce处理公共自行车数据
利用Hadoop平台处理公共自行车数据,数据Excel表如下:
Excel表中有一列duration表示自行车使用时间,利用MapReduce统计自行车使用时间为60s,120,180s以此类推的使用量。
代码如下:
Map端:
package com.tyut.rcr;import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;public class Map extends Mapper<LongWritable, Text, Text, IntWritable> {private static final IntWritable one = new IntWritable(1);protected void map(LongWritable key, Text value,org.apache.hadoop.mapreduce.Mapper<LongWritable, Text, Text, IntWritable>.Context context)throws java.io.IOException, InterruptedException {String line = value.toString();String[] datas= line.split(",");String during=datas[0];int dur = Integer.parseInt(during);if(dur<60){String str = "自行车使用时间<60s次数: "+dur;context.write(new Text(str),one);}else {for(int i=1;i<
更多推荐
MapReduce处理公共自行车数据
发布评论