HADOOP POC ON EXCEL DATA WEATHER REPORT ANALYSIS
Hello Friends, Glad to present this blog which is for analysis of Weather Report POC, which is in Excel Format. This POC was given to me and asked by one of my friends to complete it. Most of the time we get data in Excel Format and according to that we have to make changes in our coding. So, in this POC I have modified my previous code to accept the excel data, for the convenience of making you all understand the concept. NOTE:- Though this POC is to read EXCEL data, I have not used the same in my coding but still it worked. (I have no idea how & why it happened. Kindly share if you know anything on the same.) I worked out this POC on my previous POC's processed system. So all required jar files for excel reading were already there in hadoop lib folder. If you face any problem in reading the input file kindly use EXCEL INPUT FORMAT from my previous blog to read the data. UPDATE:- CORRECTION:- In this blog the Input file is not in Excel format. so it works directly without using Excel Input Format Class. (Please find the Excel Input File HERE and Compiled Coding Jar file HERE) Problem Statement: 1. The system receives temperatures of various cities captured at regular intervals of time on each day in an input file. 2. All cities weather information for a week will be inputted to the system in a single input file. 3. System will process the input data file and generates a report with Maximum and Minimum temperatures of each day. 4. Generates a separate output report for each Month. Ex: January-r-00000 February-r-00000 March-r-00000 5. Develop a PIG Script to filter the Map Reduce Output in the below fashion - Provide the Unique data - Sort the Unique data based on RETAIL_ID in DESC order 6. EXPORT the same PIG Output from HDFS to MySQL using SQOOP 7. Store the same PIG Output in a HIVE External Table. Input File Format:- .xls (EXCEL Format) This POC Input file and Problem statement was shared to me by Mr. Amol Wani which contains temperature statistics with time for multiple Months. Schema of record set is as shown in picture below :- DOWNLOAD MY INPUT FILE FROM BELOW LINK: https://drive.google.com/file/d/0BzYUKIo7aWL_WkFYdWU5QWdJLTA/view?usp=sharing 1. TO TAKE INPUT DATA ON HDFS hadoop fs -mkdir /InputData hadoop fs -put WeatherReport.txt /InputData jar xvf WeatherPoc.jar (Please find my jar file HERE) 2. MAP REDUCE CODES:- WEATHER REPORT PROCESSOR (DRIVER CLASS) NOTE:- If you face any problem in reading the input file kindly uncomment the following and add necessary class path & jar files. // job.setInputFormatClass(ExcelInputFormat.class); // job.setOutputFormatClass(TextOutputFormat.class); // LazyOutputFormat.setOutputFormatClass(job, TextOutputFormat.class); Please go through my previous blog on Any Excel Data reading. package com.poc.weather; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; import org.apache.hadoop.mapreduce.lib.output.LazyOutputFormat; import org.apache.hadoop.mapreduce.lib.output.MultipleOutputs; import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import com.poc.ExcelInputFormat; public class WeatherReportProcessor { public static String January = "January"; public static String February = "February"; public static String March = "March"; public static String April = "April"; public static String May = "May"; public static String June = "June"; public static String July = "July"; public static String August = "August"; public static String September = "September"; public static String October = "October"; public static String November = "November"; public static String December = "December"; public static void main(String[] args) throws Exception { Configuration conf = new Configuration(); Job job = new Job(conf, "Weather Report"); job.setJarByClass(WeatherReportProcessor.class); job.setMapperClass(WeatherMapper.class); job.setReducerClass(WeatherReducer.class); // job.setInputFormatClass(ExcelInputFormat.class); // job.setOutputFormatClass(TextOutputFormat.class); // LazyOutputFormat.setOutputFormatClass(job, TextOutputFormat.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); MultipleOutputs.addNamedOutput(job, January, TextOutputFormat.class, Text.class, Text.class); MultipleOutputs.addNamedOutput(job, February, TextOutputFormat.class, Text.class, Text.class); MultipleOutputs.addNamedOutput(job, March, TextOutputFormat.class, Text.class, Text.class); MultipleOutputs.addNamedOutput(job, April, TextOutputFormat.class, Text.class, Text.class); MultipleOutputs.addNamedOutput(job, May, TextOutputFormat.class, Text.class, Text.class); MultipleOu

Hello Friends,
Glad to present this blog which is for analysis of Weather Report POC, which is in Excel Format. This POC was given to me and asked by one of my friends to complete it.
Most of the time we get data in Excel Format and according to that we have to make changes in our coding. So, in this POC I have modified my previous code to accept the excel data, for the convenience of making you all understand the concept.
I worked out this POC on my previous POC's processed system. So all required jar files for excel reading were already there in hadoop lib folder.
Problem Statement:
1. The system receives temperatures of various cities captured at regular intervals of time on each day in an input file.
2. All cities weather information for a week will be inputted to the system in a single input file.
3. System will process the input data file and generates a report with Maximum and Minimum temperatures of each day.
4. Generates a separate output report for each Month.
Ex: January-r-00000
February-r-00000
March-r-00000
- Provide the Unique data
- Sort the Unique data based on RETAIL_ID in DESC order
6. EXPORT the same PIG Output from HDFS to MySQL using SQOOP
7. Store the same PIG Output in a HIVE External Table.
Input File Format:- .xls (EXCEL Format)
DOWNLOAD MY INPUT FILE FROM BELOW LINK:
https://drive.google.com/file/d/0BzYUKIo7aWL_WkFYdWU5QWdJLTA/view?usp=sharing
1. TO TAKE INPUT DATA ON HDFS
hadoop fs -mkdir /InputData
2. MAP REDUCE CODES:-
(DRIVER CLASS)
NOTE:- If you face any problem in reading the input file kindly uncomment the following and add necessary class path & jar files.
// job.setInputFormatClass(ExcelInputFormat.class);
// job.setOutputFormatClass(TextOutputFormat.class);
// LazyOutputFormat.setOutputFormatClass(job, TextOutputFormat.class);
In Mapper, after reading input data from excel, I am removing the first two lines which doesn't contain any related data, and then splitting the entire data and taking only Date and Temperatures as my output from Mapper which be be used as input for Reducer.
package com.poc.weather;
import java.io.IOException;
In Reducer phase taking the output from Mapper, I am splitting the temperatures to get max and min temp. and comparing them with other data of different hours from a single day to get the max and min temp of that day.
After getting the max and min temp, I am checking the date for sorting them into different months.
package com.poc.weather;
3. EXECUTING THE MAP REDUCE CODE
hadoop jar WeatherPoc.jar com.poc.weather.WeatherReportProcessor /InputData/WeatherReport.xls /WeatherOutput
We can clearly see that the input records is 8986 but the output is 365. ; It has sorted the data into number of days in a year which has been kept in different months as specified in coding.
A = LOAD '/WeatherReport/' USING PigStorage ('\t') AS (date:chararray, mintemp:float, maxtemp:float);
sqoop eval --connect jdbc:mysql://localhost/ --username root --password root --query "create database if not exists WEATHERPOC;";
sqoop eval --connect jdbc:mysql://localhost/ --username root --password root --query "use WEATHERPOC;";
sqoop eval --connect jdbc:mysql://localhost/WEATHERPOC --username root --password root --query "create table weatherpoc(date varchar(50), mintemp float, maxtemp float);";
create external table weatherpoc(Name string, mintemp float, maxtemp float)