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.

    Next Topic



503
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.


           

1 Answers



 
answered By   0  
import java.io.IOException;
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 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   
   add comment

Your answer

Join with account you already have

FF

Preview

 Write A Tutorials
Online-Classroom Classes
www.writeabc.com


  1 person following this question

  1 person following this tag

  Question tags

mapreduce × 1

Asked 4 years and 2 months ago ago
Number of Views -503
Number of Answers -1
Last updated
4 years and 2 months ago ago

Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!

Alert