DA Lab Program-3
DA Lab Program-3
Steps to be followed:
• Step-1: We can download the dataset from this Link, For various cities in
different years. choose the year of your choice and select any one of the
data text-file for analysing.
We can get information about data from README.txt file available on the
NCEI website.
// importing Libraries
import java.io.IOException;
import java.util.Iterator;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
1
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.conf.Configuration;
// Mapper
*/
/**
* @method map
2
*/
@Override
if (!(line.length() == 0)) {
float temp_Max =
Float.parseFloat(line.substring(39, 45).trim());
3
float temp_Min =
Float.parseFloat(line.substring(47, 53).trim());
// if maximum temperature is
// Hot day
new Text(String.valueOf(temp_Max)));
// Cold day
new
Text(String.valueOf(temp_Min)));
// Reducer
4
having four Hadoop generics type
*/
/**
* @method reduce
*/
/**
* @method main
* code.
*/
job.setJarByClass(MyMaxMin.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(Text.class);
job.setMapperClass(MaxTemperatureMapper.class);
job.setReducerClass(MaxTemperatureReducer.class);
job.setInputFormatClass(TextInputFormat.class);
6
// Defining output Format class which is
job.setOutputFormatClass(TextOutputFormat.class);
// to delete it explicitly
OutputPath.getFileSystem(conf).delete(OutputPath);
System.exit(job.waitForCompletion(true) ? 0 : 1);
7
§ Now we need to add external jar for the packages that we have
import. Download the jar package Hadoop Common and Hadoop
MapReduce Core according to the Hadoop version.
start-dfs.sh
start-yarn.sh
8
• Step-6: Now Run your Jar File with below command and produce the
output in MyOutput File.
• Step-7: Now Move to localhost:50070/, under utilities select Browse the file
system and download part-r-00000 in /MyOutput directory to see result.