Home > Software > BIGDATA > MapReduce
Interview Questions   Tutorials   Discussions   Programs   Videos

# MapReduce - A weather station in Hyderabad records weather of different areas in the city. The weather data would include temperature, rainfall, windspeed, etc. Every hour, the weather station generates a data in this format: Calculate the average temperature of each area for the date 19-July-2013.

353
views
asked amar513 October 3, 2013 03:27 AM

A weather station in Hyderabad records weather of different areas in the city. The weather data would include temperature, rainfall, windspeed, etc. Every hour, the weather station generates a data in this format: Calculate the average temperature of each area for the date 19-July-2013.

import java.io.IOException;
public class MaxTemperatureMapper
extends Mapper<LongWritable, Text, Text, IntWritable> {
private static final int MISSING = 9999;
@Override
public void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException {
String line = value.toString();
String year = line.substring(15, 19);
int airTemperature;
if (line.charAt(87) == '+') { // parseInt doesn't like leading plus signs
airTemperature = Integer.parseInt(line.substring(88, 92));
} else {
airTemperature = Integer.parseInt(line.substring(87, 92));
}
String quality = line.substring(92, 93);
if (airTemperature != MISSING && quality.matches("[01459]")) {
context.write(new Text(year), new IntWritable(airTemperature));
}
}
}
flag

### Join with account you already have

Preview

Online-Classroom Classes
www.writeabc.com

1 person following this question

1 person following this tag

Question tags

mapreduce × 1

Asked 3 years and 26 days ago ago
Number of Views -353