Weather Analysis
Weather Analysis
Develop a Map Reduce program that mines weather data and displays appropriate
messages indicating the weather conditions of the day.
Java :
Open a notepad or editor and save the below program as WeatherAnalysis.java
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
String condition;
if (temperature >= 35) {
condition = "Hot";
} else if (temperature <= 15) {
condition = "Cold";
} else {
condition = "Moderate";
}
job.setJarByClass(WeatherAnalysis.class);
job.setMapperClass(WeatherMapper.class);
job.setReducerClass(WeatherReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
c:\Users\KUMARESH\Documents>javac -classpath
"C:\hadoop\share\hadoop\common\*;C:\hadoop\share\hadoop\common\lib\*;C:\hadoop\share\
hadoop\mapreduce\*;C:\hadoop\share\hadoop\mapreduce\lib\*;C:\hadoop\share\hadoop\hdfs\
*;C:\hadoop\share\hadoop\hdfs\lib\*" -d classes WeatherAnalysis.java
Output:
c:\Users\KUMARESH\Documents>hdfs dfs -cat /output4/part-r-00000