Skip to main content
Open navigation menu
Close suggestions
Search
Search
en
Change Language, English
Upload
Sign in
Sign in
0 ratings
0% found this document useful (0 votes)
11 views
15 pages
Map Reduce
Uploaded by
SL MA
AI-enhanced title
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save MapReduce For Later
Share
0%
0% found this document useful, Mark this document as useful
0%
0% found this document not useful, Mark this document as not useful
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
11 views
15 pages
Map Reduce
Uploaded by
SL MA
AI-enhanced title
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Go to previous items
Download
Save
Save MapReduce For Later
Share
0%
0% found this document useful, Mark this document as useful
0%
0% found this document not useful, Mark this document as not useful
Print
Embed
Report
Go to next items
Download
Save MapReduce For Later
Share
More options
Fullscreen
1.1 Load and examine the sample data 1. You should start with a window like this after you log in ee =o) In the PuTTY window, examine the directory structure of the hadoop file system of your directory. Type: You want to make a new directory to store the sample data files that you will use for this, exercise. Make a new directory called sampledata/, and verify that it was created. Type: mkdir sampl__4. Now, to move BDU_MapReduce_and_YARN.tar file into cloud. Open up WinSCP and transfer the file to your home directory. Just drag the file from the left side to the home directory on the right side. 3 Dewnenwentoa eCioale +@ euaaie (Cueeaion ApMNDanwats 5. Then extract the file.Now your window should show something similar when it's done extracting the files. Now that the files are extracted, we will upload the temperature data from the local file system to the HDFS using the following commands: ~/labfiles/SumnerCount yTemp. da Test to see that the file was uploaded correctly by typing the following command: hd£s ¢ ls edata Notice that your [Link] files was uploaded correctly. You can view this data by executing the following command: hdfs df moreThe values in the 95th column (354, 353, 353,353, 352, ...) are the average daily temperatures. They are the result of multiplying the actual average temperature value times 10. (Incidentally, that way you don't have to worry about working with decimal points.) Press the spacebar a few times to scroll through the data and observe the temperature patterns by date. When you are satisfied, press Ctri+c to break out of the piped output.1.2 Start your Java project Create a directory to hold the three Java files that you will be making and make it accessible. The directory will be used to hold program artifacts and to separate it from the other things in the file system. cr mkdir [Link] name cd [Link]1.3 Create the Java file for the mapper class Create @ new Java file, [Link]: vi MaxTempMapper There is a standard set of imports that will also be used for the other two Java files that you create. The data type for the input key to the mapper will be LongWritable. The data itself will be of type Text. The output key trom the mapper will be of type Text. And the data from the mapper (the temperature) will be of type IntWritable. You need a public class with name MaxTempMapper. For this class, ___a. You will need to import [Link].|OException. __b. Extend Mapper
Define a public class called map. d. Your code should look like the following: import [Link]. IOException; import org. mport org. import org. mport org. [Link]-Intwritable; ache .[Link]; [Link]; pache .[Link] Mapper; public class MaxTempMapper extends Mapper
[ @override public void map(Longiiritable key, Text value, Context context) throws IOException, InterruptedException { In the next section you will define the map method. Note: You can also create the java file in notepad and transfer it via WinSCP1.4 Complete the mapper ‘Your program will read in a line of data as a string so that you can do string manipulation. You will want to extract the month and average temperature for each record. The month begins at the 22th character of the record (zero offset) and the average temperature begins at the 95th character. (Remember that the average temperature value is three digits, with implied one decimal place). __1. Inthe map method, add the following code (or whatever code you think is required): String line - [Link](); String month = [Link] (22,24) ; int avgTemp; avgTemp ~ [Link] (Line. substring (95, 98) ) context .weite(new Text (month), new IntWritable(avgTemp)) ; 2, From this document, you may wish to copy the entire content of the file into Windows Notepad where you can insert the code for the map method. Then transfer the java file (for ex: ‘MaxTempMapper java) to your [Link] folder. Ifyou are using f press Ese, and then type :wq|to write and exit the vi editor and write your file or Press Esc then hit Shift + z twice.Create the reducer class Create a new Java file, [Link]: vi MaxTempReducer.. java You need a public class with name MaxTempReducer and the data type for the input key to the reducer will be Text. The data itself will be of type /ntWWritable. The output key from the reducer will be of type Text. And the data from the reducer will be of type IntWritable. For your class, a. You will need to import [Link] b. Extend ReducercText, LongWritable, Text, IntWritable> ©. Define a public class called reduce. d. Your code should look like the following: import [Link]. IOException; Inport [Link].10-Intwritable; import [Link]; import [Link] Reducer} public class MaxTempReducer extends Reducer
{ @override public void reduce (Text key, Iterable values, Context context) throws IOException, Interruptedixception { }Complete the reducer For the reducer, you want to iterate through all values for a given key. For each value found, check to see if itis higher than any of the other values, Add the following code (or your variation) to the reduce method. int maxTemp = Integer.MIN_VALUE; for (IntWritable value: values) [ maxTemp = [Link](maxTemp, [Link] ()¢ [Link] (key, new IntWritable(maxTemp)}; Assemble your file in the vi editor, notepad or any way you choose, and remember to save your work.17 Create the driver Create a new Java file, [Link]: vi MaxMonthTemp, java ‘You need a public class with name MaxMonthTemp and the standard set of import files. The GenericOptionsParser() will extract any input parameters that are not system parameters and place them in an array. In your case, two parameters will be passed to your application. The first parameter is the input file. The second parameter is the output directory. (This directory must not exist or your MapReduce application will fail.) Your code should look like this: import [Link] ion; import [Link]; import [Link]; import [Link]; import [Link] .mapreduce . Job; import [Link] .FileInputFormat; import [Link]. [Link].1ib,output .FileoutputFormat; import [Link] ionsParser; public class MaxMonthTemp { public static void main(String[) args) throws Exception ( Configuration conf - new Configuration (); String|] programArgs new GenericOptionsParser (conf, args) .getRemainingaArgs (); if ([Link] != 2) ( [Link]("Usage: MaxTemp "); [Link] (2); ) Job job - [Link] (conf, "Monthly Max Temp"); Job. set JarByClass ([Link]) job. setMapperClass ([Link]) ; job. setReducerClass ([Link]) ; job. setOutputKeyClass (Text class); job. set Output ValueClass (IntWritable. class); [Link] (job, new Path (programArgs[0])); FileOutputFormat .setOutputPath (job, new Path (programArgs[1])}7 nit the 35h and wate pth cinien [Link] ([Link](true) 2.0: 1);__2. Assemble your file in the vi editor any way you choose, and remember to save your work.Compile your Java files & create the JAR file Compile all three Java files with one statement as the root user and then list your directory to see that you now have three Java source files and three Java class files. Type: any .name sspath’ *, java Note that the quotes here are back-quotes (the key to top left comer of your keyboard, to the left of the one-key ["1’}). The command hadoop classpath is executed to list the required classpath information needed by the compiler; the result of this is passed to javac with the classpath option Cop). TnpatPath(job, neu Path(pragranargs(@1)) faxtlonthTemp. java!29: error: unmappable character for encoding UTES Sincere titan nett TonC TEE) HonthTemp. java:29: crror: unmappable character for cncoding UTEB Pe ee reet en a en entero etC TTD Ce eee ee oe eee Em Sarre ier eeeet neers Exnrenerietere cthyy See eee er ee oe Seprerti een Ret oe So strie eees) i Roe ie re eo mc) ees re eve eS een) toe ‘This meant that you copied & pasted directly from this document while using a program that converted some of the whitespaces into a different format. To correct this, open notepad from windows and/or vi and delete the characters that give you an error and replace it with a typed character of itself. (Ex, replace the above boxes, which show up as spaces on your editor with spaces typed from your keyboard),Create a Java Archive File (jar cf, where c = create, f = file) from the three class files. Then list the manifest (jar tf) of the archive file [Link] *.c The Java Archive File was created in the directory where the ,java and .class files reside. But when we use Hadoop MapReduce to run the jar, Hadoop does not like to have the .class files in the same directory. Therefore you want to move the file to the parent directory, where we will run itin the next step:1.9 Run the JAR file 1. Run the application. Type: nadoop jar ./MaxMT. jar MaxMonthTe data/Tempout sampledata/Su yTemp. dat samp You will see the following output in that terminal window (but your results will be slightly different, of course): Nm aye det VB <= ee ees eee Besos eet ey eat Nun ras eas assBap mae ereirs eae Mee Your results are certainly different, but the final lines of output will probably be similar. You want to examine the output that was produced: The result of this run should be similar to: Fr Be aware that if you cut & paste from this file, sometimes Microsoft and Adobe software change a single dash (“") to an en-dash (’-") or an em-dash ('—’). Linux is not kind to these characters. You can see that the maximum temperature for January (01) was 36.7 F — this is the coldest month of Winter in Sumner County as evidenced by the data — and the maximum temperature for July (07) was 78.5 F for the County (a rather cool summer, it appears)
You might also like
Weather Data Processing with MR Program
PDF
No ratings yet
Weather Data Processing with MR Program
9 pages
MapReduce Hands On
PDF
100% (1)
MapReduce Hands On
28 pages
Hadoop MapReduce Java Programming Guide
PDF
No ratings yet
Hadoop MapReduce Java Programming Guide
13 pages
Weather Data Analysis with MapReduce
PDF
No ratings yet
Weather Data Analysis with MapReduce
46 pages
Yearly Max Temperature MapReduce Code
PDF
No ratings yet
Yearly Max Temperature MapReduce Code
9 pages
Assignment Adithya
PDF
No ratings yet
Assignment Adithya
21 pages
Big Data Lab Manual: Hadoop & Spark
PDF
No ratings yet
Big Data Lab Manual: Hadoop & Spark
86 pages
Da Record
PDF
No ratings yet
Da Record
37 pages
Max Temperature Analysis with MapReduce
PDF
No ratings yet
Max Temperature Analysis with MapReduce
21 pages
Hadoop Temperature Data Processing
PDF
No ratings yet
Hadoop Temperature Data Processing
4 pages
Max Temperature Analysis with Hadoop
PDF
No ratings yet
Max Temperature Analysis with Hadoop
22 pages
MR Progs Discussed in Classes
PDF
No ratings yet
MR Progs Discussed in Classes
6 pages
Unit 3
PDF
No ratings yet
Unit 3
32 pages
Weather Data Analysis with MapReduce
PDF
No ratings yet
Weather Data Analysis with MapReduce
6 pages
Weather Data
PDF
No ratings yet
Weather Data
4 pages
Running MapReduce in Eclipse Setup
PDF
No ratings yet
Running MapReduce in Eclipse Setup
6 pages
E1 Hadoop
PDF
No ratings yet
E1 Hadoop
52 pages
MR YARN - Lab 1 - Cloud - Updated-V2.0
PDF
No ratings yet
MR YARN - Lab 1 - Cloud - Updated-V2.0
30 pages
Running WordCount in Hadoop on Windows
PDF
No ratings yet
Running WordCount in Hadoop on Windows
7 pages
Weather Data Analysis with Hadoop 3.3.6
PDF
No ratings yet
Weather Data Analysis with Hadoop 3.3.6
6 pages
Java MapReduce Weather Data Analysis
PDF
No ratings yet
Java MapReduce Weather Data Analysis
4 pages
Developing MapReduce Applications in Hadoop
PDF
No ratings yet
Developing MapReduce Applications in Hadoop
30 pages
Analyzing Weather Data with MapReduce
PDF
No ratings yet
Analyzing Weather Data with MapReduce
12 pages
MapReduce for Weather Data Analysis
PDF
No ratings yet
MapReduce for Weather Data Analysis
12 pages
Hadoop Setup and Commands Guide
PDF
No ratings yet
Hadoop Setup and Commands Guide
1 page
Hadoop Tasks Map Reduce PRGS (Lab)
PDF
No ratings yet
Hadoop Tasks Map Reduce PRGS (Lab)
26 pages
MapReduce Partitioner Tutorial
PDF
No ratings yet
MapReduce Partitioner Tutorial
8 pages
First Map-Reduce Program in Hadoop
PDF
No ratings yet
First Map-Reduce Program in Hadoop
22 pages
Java MapReduce Program Examples
PDF
No ratings yet
Java MapReduce Program Examples
10 pages
MapReduce Weather Data Analysis
PDF
No ratings yet
MapReduce Weather Data Analysis
14 pages
Hadoop Single Node Setup Guide
PDF
No ratings yet
Hadoop Single Node Setup Guide
61 pages
MapReduce Programs for Data Analysis
PDF
No ratings yet
MapReduce Programs for Data Analysis
33 pages
Hadoop 3.3.1 Installation Guide
PDF
No ratings yet
Hadoop 3.3.1 Installation Guide
19 pages
Map Reduce
PDF
No ratings yet
Map Reduce
45 pages
Max Temperature Analysis with Hadoop
PDF
No ratings yet
Max Temperature Analysis with Hadoop
13 pages
Hadoop MapReduce Programming Guide
PDF
No ratings yet
Hadoop MapReduce Programming Guide
12 pages
Hadoop File Management and MapReduce Guide
PDF
No ratings yet
Hadoop File Management and MapReduce Guide
45 pages
MapReduce Programs for Data Analysis
PDF
No ratings yet
MapReduce Programs for Data Analysis
6 pages
Hadoop File Management and MapReduce Guide
PDF
No ratings yet
Hadoop File Management and MapReduce Guide
10 pages
MapReduce Notes1
PDF
No ratings yet
MapReduce Notes1
20 pages
Understanding Hadoop MapReduce Basics
PDF
No ratings yet
Understanding Hadoop MapReduce Basics
115 pages
CCS334 Big Data Analytics Manual
PDF
No ratings yet
CCS334 Big Data Analytics Manual
80 pages
Java and Hadoop Installation Guide
PDF
No ratings yet
Java and Hadoop Installation Guide
14 pages
Data Science Laboratory Lab Manual
PDF
No ratings yet
Data Science Laboratory Lab Manual
82 pages
MapReduce for Weather Data Analysis
PDF
No ratings yet
MapReduce for Weather Data Analysis
77 pages
Big Data Experiments with Hadoop and R
PDF
No ratings yet
Big Data Experiments with Hadoop and R
30 pages
Big Data Analytics Lab Record
PDF
No ratings yet
Big Data Analytics Lab Record
17 pages
Understanding MapReduce for Temperature Data
PDF
No ratings yet
Understanding MapReduce for Temperature Data
32 pages
Classic MapReduce Overview and Example
PDF
No ratings yet
Classic MapReduce Overview and Example
8 pages
Apache Hadoop Partitioner Lab Exercise
PDF
No ratings yet
Apache Hadoop Partitioner Lab Exercise
12 pages
Hadoop Installation and MapReduce Guide
PDF
No ratings yet
Hadoop Installation and MapReduce Guide
42 pages
Big Data Weather Report Analysis
PDF
No ratings yet
Big Data Weather Report Analysis
5 pages
Lab Programs
PDF
No ratings yet
Lab Programs
33 pages
Unit III (Ai&Ds) Final
PDF
No ratings yet
Unit III (Ai&Ds) Final
14 pages
Install JRE 1.8.0_441 for Hadoop Setup
PDF
No ratings yet
Install JRE 1.8.0_441 for Hadoop Setup
41 pages
Java MapReduce Setup and Execution Guide
PDF
No ratings yet
Java MapReduce Setup and Execution Guide
8 pages
BDA Lab Manual: MapReduce Programs
PDF
No ratings yet
BDA Lab Manual: MapReduce Programs
23 pages