Lecture 7 - Practice MapReduce with EMR

Updated 12 Nov 2026

Roadmap

  • Practice MapReduce With Amazon EMR (hands-on lab)
  • Your Assignment Tasks
    • Follow tutorial steps and capture screen along the way
    • Complete an exercise
  • Steps
    • Create Amazon EMR
    • Access Web UI of HDFS, YARN
    • Create Wordcount MapReduce
    • Run Wordcount on EMR
    • Check Result on CLI
    • Check Result file on HDFS
    • Check MapReduce process on YARN
  • Exercise: Create MapReduce program to list unique ID with total count of each ID

Related


Your Assignment Tasks

  1. Follow Tutorial Steps and capture screen along the way
  2. Complete an exercise
  • Slides marked CAPTURE SCREEN = take a screenshot for your submission
    • AWS EMR: Ready to use
    • Test Web Access for HDFS GUI
    • Test Web Access for YARN GUI
    • Ready to Run MapReduce
    • Execute MapReduce job
    • Check Result from CLI
    • Check Result file on HDFS
    • Check MapReduce process on YARN

Steps (Overview)

  • Tutorial
    • Create Amazon EMR
    • Access Web UI of HDFS, YARN
    • Create Wordcount MapReduce
    • Run Wordcount on EMR
    • Check Result on CLI
    • Check Result file on HDFS
    • Check MapReduce process on YARN
  • Exercise
    • Create MapReduce Program to list of unique ID with total count of each id

Think of the lab as a cooking class: first the chef (tutorial) shows you how to make one dish (WordCount) step by step, then you cook a slightly different dish on your own (count taxi IDs) using the same recipe pattern.


Hadoop on Cloud: AWS EMR

  • Access to AWS Learner Lab (50 USD credits)
  • Select EMR service and click "Create cluster"
  • EMR will stop after some time or after stop lab
    • For next time, you can select "Clone" (copies the previous cluster's settings)

  • Amazon EMR (Elastic MapReduce) = AWS's managed Hadoop/Spark cluster service
    • AWS sets up the machines (EC2), installs Hadoop & friends, and connects them for you

EMR is like renting a fully-furnished apartment instead of building a house: you pick the size and the furniture (Hadoop, Spark, Hive...), AWS builds it in ~10 minutes, and you just move in and start working.


AWS EMR: Choose Big Data Framework

  • Define Cluster Name (e.g. My cluster)
  • Select EMR version: emr-7.9.0
    • It matches with some version of the Hadoop ecosystem (e.g. Hadoop 3.4.1)
  • Select only services you want (Application bundle → Custom):
    • Hadoop, Tez
    • Hive, Hue, Pig
    • Spark, Livy
    • JupyterHub, Zeppelin

ServiceWhat it is (quick idea)
HadoopHDFS (storage) + YARN (resource manager) + MapReduce
TezFaster execution engine used by Hive/Pig
HiveSQL-like queries on Hadoop data
HueWeb UI for Hadoop (browse files, run queries)
PigScripting language for data flows on Hadoop
SparkIn-memory big data processing engine
LivyREST service to submit Spark jobs
JupyterHub / ZeppelinWeb notebooks for data analysis

AWS EMR: Select Hardware

  • Select Instance groups (Uniform instance groups)
  • 1 Primary node and 2 Core nodes
  • Select m4.large (2 vCore, 8 GiB memory, EBS only storage)
  • No task node
  • Cluster scaling: Set cluster size manually → Core instance size = 2

  • Node roles:
    • Primary node (master) — runs the NameNode (HDFS) and ResourceManager (YARN); you SSH into this one
    • Core nodes — run DataNode (store HDFS blocks) and NodeManager (run map/reduce tasks)
    • Task nodes — only compute, no HDFS storage (not used here)
Cluster=1 Primary+2 Core+0 Task\boxed{\text{Cluster} = 1 \text{ Primary} + 2 \text{ Core} + 0 \text{ Task}}

Primary node = the team manager who keeps the to-do list and knows where every file is. Core nodes = the workers who both store the files and do the work. Task nodes = temp workers who only help with work (we don't hire any).


AWS EMR: Select Network

  • Use default VPC and subnet (no need to change anything)
  • EC2 security groups (firewall) are created automatically:
    • Primary node → Create ElasticMapReduce-Primary
    • Core and task nodes → Create ElasticMapReduce-Core


AWS EMR: Cluster Termination and Node Replacement

  • Cluster termination and node replacement: Set 3 hours
    • Termination option: Automatically terminate cluster after idle time (Recommended)
    • Idle time: 0 days 03:00:00
    • (Time must be > 1 minute and < 7 days, hh:mm:ss 24-hour format)
  • Use termination protection ✓ — protects the cluster from accidental shutdown (must turn off protection before terminating)
  • Unhealthy node replacement: Turn on — EMR gracefully stops processes on unhealthy nodes and replaces them with new EC2 instances

Auto-terminate after idle = a "sleep timer" on your TV. If you forget to turn the cluster off, it shuts itself down after 3 hours of doing nothing, so you don't burn your 50 USD credits.


AWS EMR: Assign Cluster Logs

  • Check name of default S3 bucket location
    • e.g. s3://aws-logs-<account-id>-us-east-1/elasticmapreduce
    • ✓ Publish cluster-specific logs to Amazon S3
  • Go to S3 to create S3 bucket with the same name (e.g. aws-logs-<account-id>-us-east-1)


AWS EMR: Assign Security Key Pair

  • For remote access to cluster, assign security key pair: select vockey
    • Field: Amazon EC2 key pair for SSH to the cluster
  • Keypair download from AWS Details of learner lab
  • Download PEM

  • PEM = private key file used by ssh (Mac/Linux, MobaXterm)
  • PPK = PuTTY format of the same key (Windows PuTTY)

The key pair is like a lock-and-key set: AWS puts the lock (vockey public key) on the cluster's door, and you keep the key (.pem file). Without the key, nobody can SSH in.


AWS EMR: Assign Instance Profile and Service Role

  • Assign EMR Service Role
    • Choose an existing service role → EMR_DefaultRole
    • The service role is an IAM role that EMR assumes to provision resources and perform service-level actions with other AWS services
  • Instance profile assigns a role to every EC2 instance in a cluster
    • Choose an existing instance profile → EMR_EC2_DefaultRole
    • Must specify a role that can access the resources for your steps and bootstrap actions (e.g. S3)

RoleWho uses itPurpose
EMR_DefaultRoleThe EMR service itselfCreate/manage EC2 instances, networking, etc.
EMR_EC2_DefaultRoleEach EC2 node in the clusterRead/write S3, write logs, etc.

Service role = the permission slip for the contractor (EMR) to build the house. Instance profile = the badge each worker (EC2 node) wears so they can enter the storage room (S3).


AWS EMR: Create Cluster

  • Click Create cluster
  • It may take up to 10 minutes for the cluster to start
    • Status shows Starting at first


AWS EMR: Ready to Use

CAPTURE SCREEN

  • Wait until status shows Waiting
    • Waiting = cluster is up and idle, ready to accept jobs
  • Use Primary node public DNS for remote connection
    • e.g. ec2-xx-xx-xx-xx.compute-1.amazonaws.com

  • Cluster states: Starting → Bootstrapping → Running → Waiting (→ Terminating → Terminated)

AWS EMR: Ready to Use — Application UIs

  • Check application UI for each service (Applications tab → Application UIs on the primary node)
    • These require SSH tunneling to be enabled (or opening the port in the firewall, see below)
ApplicationPortURL pattern
HDFS Name Node9870http://<primary-dns>:9870/
Hue8888http://<primary-dns>:8888/
JupyterHub9443https://<primary-dns>:9443/
Livy8998http://<primary-dns>:8998/
Resource Manager (YARN)8088http://<primary-dns>:8088/
Spark History Server18080http://<primary-dns>:18080/
Tez UI8080http://<primary-dns>:8080/tez-ui
Zeppelin8890http://<primary-dns>:8890/


AWS EMR: Add SSH Allow on Firewall

  • For best practice, we should not allow anyone to access the cluster
  • So, we will allow only specific IP or subnet to access
  • First, check your public IP: go to Google and type my ip
  • Then, allow this IP to access cluster
    • If you change network, IP may change (→ must update the rule again)

A security group is the building's security guard with a guest list. By default nobody from outside is on the list. You add only your own IP so the guard lets just you in — if you move to another Wi-Fi (new IP), the guard won't recognize you until you update the list.


AWS EMR: Add SSH Allow on Firewall (Steps)

  • Go to security group of primary node (Properties → Network and security → EC2 security groups → Primary node sg-...)
  • Click link and select Edit inbound rule
  • Add new rule with SSH and source is your public IP
    • Type: SSH, Protocol: TCP, Port range: 22
    • Source: Custom → <your-public-ip>/32
    • Description: SSH access
  • Save Rule

  • /32 = CIDR notation meaning exactly one IP address (all 32 bits fixed)
Number of IPs in a /n block=232−n⇒/32→20=1 IP\boxed{\text{Number of IPs in a } /n \text{ block} = 2^{32-n}} \quad\Rightarrow\quad /32 \to 2^{0} = 1 \text{ IP}

AWS EMR: Add Allow GUI Access on Firewall

  • Add port: 9870 and 8088 for HDFS GUI and YARN GUI (allow only your public IP)
  • On Security group of primary node (ElasticMapReduce-master)
TypeProtocolPortSourceDescription
SSHTCP22<your-ip>/32SSH
Custom TCPTCP9870<your-ip>/32HDFS
Custom TCPTCP8088<your-ip>/32YARN


Test Web Access for HDFS GUI

CAPTURE SCREEN

  • Open http://Change-to-your-primary-dns-name:9870
http://<primary-node-public-dns>:9870

  • What you see:
    • Overview — NameNode is active, Hadoop version 3.4.1-amzn-1
    • Summary — Security off, Safemode off, number of files & blocks, heap memory
    • Datanodes tab — should show 2 live DataNodes (the 2 core nodes)
  • Note: Hadoop 3 uses port 9870 for the NameNode UI (older Hadoop 2 used 50070)

Test Web Access for YARN GUI

CAPTURE SCREEN

  • Open http://Change-to-your-primary-dns-name:8088
http://<primary-node-public-dns>:8088

  • What you see:
    • Cluster Metrics — Apps Submitted / Pending / Running / Completed, Memory Total, VCores Total
    • Cluster Nodes Metrics — Active Nodes = 2
    • Scheduler — Capacity Scheduler
    • Application list is empty (no job run yet)

HDFS UI (9870) = the warehouse inventory screen (what files are stored where). YARN UI (8088) = the factory job board (which jobs are running, finished, or failed).


Use MobaXterm to Remote SSH to EMR (Windows)

  • For Windows: https://mobaxterm.mobatek.net/download.html
  • Select Home Edition (Free)
    • Full X server and SSH support, remote terminal (SSH, telnet, rlogin, Mosh), X11-forwarding, automatic SFTP browser, max 12 sessions, max 2 SSH tunnels, etc.


Another Option for SSH

  • Check learner lab detail under Modules → Launch AWS Academy Learner Lab
  • Check link SSH Access from Windows or SSH Access from a Mac (in the Readme)
  • Follow instruction


Use MobaXterm to Remote SSH to EMR (Session Setup)

  • Create new session → SSH
  • Host: copy from Primary node public DNS
  • User: hadoop
  • Port: 22
  • Private key: download PEM from AWS Details of lab learner
    • Advanced SSH settings → ✓ Use private key → select labsuser.pem


For Mac

  • Download PEM (AWS Details → SSH key → Download PEM)
  • Open terminal and run:
cd ~/Downloads
  • Change the permissions on the key (check .pem filename, use the latest one):
chmod 400 labsuser.pem
  • Run ssh command to connect server:
ssh -i <filename>.pem hadoop@<Primary-node-public-dns>

  • Why chmod 400? → ssh refuses to use a private key that other users can read
    • 400 = owner read-only, no permission for group/others
400=(r − −)owner (− − −)group (− − −)others\boxed{400 = (r\,{-}\,{-})_{\text{owner}}\ (-\,-\,-)_{\text{group}}\ (-\,-\,-)_{\text{others}}}

Ready to Run MapReduce!

CAPTURE SCREEN

  • If it works, you should see the EMR logo and prompt for running CLI
    • Prompt looks like [hadoop@ip-172-31-xx-xx ~]$


Your PC vs Primary Node vs Hadoop Cluster

  • To prepare data for processing on Hadoop (HDFS) — 2 hops:
    1. Upload file to primary node (Your PC → EMR Primary Node, via SSH/SCP/SFTP)
    2. Import file on primary node to HDFS (Primary Node local disk → EMR Hadoop Service, via hadoop fs -put)
  • To run MR program:
    • Upload program (.jar) to primary node
    • Execute program (from the terminal of the primary node)

Your PC  ──(scp / SFTP upload)──►  Primary node local disk  ──(hadoop fs -put)──►  HDFS
 book.txt, MRWordCount.jar          /home/hadoop/book.txt                          /wordcount/book.txt
  • Important distinction:
    • Local file system of primary node (/home/hadoop/...) ≠ HDFS (/wordcount/...)
    • The jar stays on the local disk (run with hadoop jar)
    • The data must be in HDFS (MapReduce reads input from HDFS)

Your PC = your home. Primary node = the front desk of a warehouse. HDFS = the actual warehouse shelves. You first carry the box to the front desk (upload), then the front desk puts it on the shelves (hadoop fs -put). Workers (mappers) only pick items from the shelves, never from the front desk.


Create Your First Program: Word Count

  1. Prepare Java Development Environment
  2. Prepare library for Hadoop and MapReduce
  3. Create Mapper class
  4. Create Reducer class
  5. Create Main program
  6. Build Jar file
  7. Upload Jar file to Hadoop cluster
  8. Upload data file to HDFS
  9. Execute job

Prepare Java Development Environment

  • Use Eclipse (it can be any version) for Java Development with JDK 1.8
  • https://www.eclipse.org/downloads/packages/
    • Download Eclipse IDE for Java Developers (Windows x86_64 / macOS x86_64 | AArch64 / Linux x86_64 | AArch64)


Prepare Java Development Environment — Project Setup

  • Create project MRWordcount
  • Define package as your student id
  • Create three files: WordCountDriver, WordCountMapper, WordCountReducer
  • Create folder lib and copy Hadoop and MapReduce lib to lib folder
    • hadoop-common-2.10.2.jar
    • hadoop-mapreduce-client-core-2.10.2.jar
  • Add them to the Java Build Path → Libraries (Add JARs...)

  • Provided tutorial files (MRTutorialData/):
MRTutorialData/
├── data/
│   ├── book.txt        ← input for WordCount (a book, ~7,426 lines, ~364 KB)
│   └── taxi.csv        ← input for the Exercise (~255,000 rows)
├── lib/
│   ├── hadoop-common-2.10.2.jar
│   └── hadoop-mapreduce-client-core-2.10.2.jar
└── src/
    ├── WordCountDriver.java
    ├── WordCountMapper.java
    └── WordCountReducer.java

Prepare Java Development Environment — Compiler Level

  • After creating the Java project, select Properties → Java Compiler
  • ✓ Enable project specific settings and select compiler compliance level: 1.8

  • Why 1.8? → The jar is compiled on your PC but runs on the cluster's Java; compiling for Java 8 bytecode keeps it compatible with the cluster's JVM

Create Mapper Class

  • For each line, split with white space and iterate over the words
  • Output with word as key and one as value
package des431;
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 WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable>{    
 
	public void map(LongWritable key, Text value,Context con) throws IOException, InterruptedException{    
         
		 String line = value.toString();  //Get All lines from the input files
         String[] words=line.split(" ");  //Extract all the words
         for(String word: words )
         {
           Text outputKey = new Text(word.toUpperCase().trim());
           IntWritable outputValue = new IntWritable(1);
           con.write(outputKey, outputValue);
         }
     }    
 
}
  • Mapper<LongWritable, Text, Text, IntWritable> = Mapper<KEYIN, VALUEIN, KEYOUT, VALUEOUT>
    • KEYIN LongWritable — byte offset of the line in the file (not used)
    • VALUEIN Text — the line of text
    • KEYOUT Text — the word
    • VALUEOUT IntWritable — the number 1
  • word.toUpperCase().trim() → "the", "The", "THE" all become THE (case-insensitive count)
  • con.write(...) → emits the intermediate pair ⟨word,1⟩\langle word, 1 \rangle
map:⟨offset, line⟩→list(⟨word, 1⟩)\boxed{\text{map}: \langle offset,\ line \rangle \rightarrow list(\langle word,\ 1 \rangle)}

The mapper is a person reading one line at a time and shouting "HELLO, 1!", "WORLD, 1!" for every word they see — they don't count anything, they just call out each word.


Create Reducer Class

  • For each key, sum number of word over the input (intermediate output from mapper)
  • Output with word as key and sum of value
package des431;
import java.io.IOException;
import java.util.Iterator;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
 
public class WordCountReducer extends Reducer<Text, IntWritable, Text, IntWritable>{
 
	@Override
	protected void reduce(Text key, Iterable<IntWritable> values, Context c) throws IOException, InterruptedException {
		int sumOfValues = 0;
		Iterator<IntWritable> valuesIt = values.iterator();
		//Aggregate the values
		while(valuesIt.hasNext()){
			sumOfValues = sumOfValues + valuesIt.next().get();
		}
		c.write(key, new IntWritable(sumOfValues));
	}	
}
  • Reducer<Text, IntWritable, Text, IntWritable> = input ⟨word,list(1,1,… )⟩\langle word, list(1, 1, \dots) \rangle → output ⟨word,total⟩\langle word, total \rangle
    • Reducer input types must match the mapper's output types
  • After shuffle & sort, each reduce() call gets one word and all of its 1s
count(w)=∑i=1nviwhere each vi=1\boxed{\text{count}(w) = \sum_{i=1}^{n} v_i \quad \text{where each } v_i = 1} reduce:⟨word, list(1,1,…,1)⟩→⟨word, sum⟩\boxed{\text{reduce}: \langle word,\ list(1,1,\dots,1) \rangle \rightarrow \langle word,\ \text{sum} \rangle}

After the shuffle, each reducer is like a vote counter who gets a bag with all ballots for one candidate. They just count the ballots in the bag and write "CANDIDATE: total".


Create Main Class (Driver)

  • Configure Job, assign name and main class
  • Set Mapper and Reducer
  • Set Output key and value
  • Set Input and Output path
  • Execute the job
package des431;
 
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.mapreduce.Job;
 
public class WordCountDriver {
	public static void main(String[] args) throws Exception {
		 
		 //Configure Job
		 Job job = Job.getInstance(new Configuration());
		 job.setJobName("WordCounter");
		 job.setJarByClass(WordCountDriver.class);
		 
		//Configure Mapper and Reducer class
		 job.setMapperClass(WordCountMapper.class);
		 job.setReducerClass(WordCountReducer.class);
 
		 //Setting the expected types of output.
		 job.setOutputKeyClass(Text.class);
		 job.setOutputValueClass(IntWritable.class);
		 job.setOutputFormatClass(TextOutputFormat.class);
		 
		//Configure Input and Output directories.
		FileInputFormat.addInputPath(job, new Path(args[0])); 
		FileOutputFormat.setOutputPath(job, new Path(args[1]));
			
		//Start the job
		System.exit(job.waitForCompletion(true) ? 0 : 1);
 
	}
}
  • Line by line:
    • Job.getInstance(new Configuration()) — create a new job using the cluster config
    • setJobName("WordCounter") — the name you will see in the YARN UI
    • setJarByClass(...) — tells Hadoop which jar to ship to the worker nodes
    • setMapperClass / setReducerClass — plug in your Mapper & Reducer
    • setOutputKeyClass(Text) / setOutputValueClass(IntWritable) — final output types
    • TextOutputFormat — writes each pair as key<TAB>value per line
    • args[0] = input path (HDFS), args[1] = output path (HDFS, must not exist yet)
    • waitForCompletion(true) — run the job and print progress; exit code 0 = success, 1 = failed

The Driver is the project manager's job ticket: "Job name: WordCounter. Readers: WordCountMapper. Counters: WordCountReducer. Take boxes from /wordcount, put results in /wordcount_output. Go!"


Build Jar File

  • Right click at project and select Export
  • Select Java → JAR file
  • Select resource (the MRWordCount project)
  • Select export destination
    • Path
    • Filename (e.g. MRWordCount.jar)
  • Finish → produces MRWordCount.jar

  • JAR (Java ARchive) = a zip of your compiled .class files — this is what Hadoop runs
  • The Hadoop libraries do not need to be inside the jar — the cluster already has them

Upload Jar File to Hadoop Cluster

  • Connect to Hadoop cluster via ssh
    • You can use MobaXterm software, upload MRWordCount.jar and book.txt (from assignment)
    • MobaXterm's left SFTP panel (/home/hadoop/) → click the upload (↑) button
  • On Mac/Linux you can use scp instead:
scp -i labsuser.pem MRWordCount.jar book.txt hadoop@<Primary-node-public-dns>:/home/hadoop/


Upload Data to HDFS

  • First upload file to Hadoop cluster (local path). Use file: book.txt from Assignment
  • Use mkdir command to create an input directory in HDFS
$HADOOP_HOME/bin/hadoop fs -mkdir /wordcount
# Or
hadoop fs -mkdir /wordcount
  • Use put command to copy the input file (document.txt) to the input directory of HDFS
$HADOOP_HOME/bin/hadoop fs -put /home/hadoop/book.txt /wordcount
  • Use ls command to verify the files in the input directory of HDFS
$HADOOP_HOME/bin/hadoop fs -ls /wordcount

CommandMeaning
hadoop fs -mkdir <dir>Create a directory in HDFS
hadoop fs -put <local> <hdfs>Copy a file from local disk → HDFS
hadoop fs -ls <dir>List files in HDFS
hadoop fs -cat <file>Print a file in HDFS

hadoop fs -<cmd> works just like normal Linux commands (mkdir, ls, cat), except it acts on the HDFS warehouse, not the primary node's own disk.


Execute MapReduce Job

CAPTURE SCREEN

  • Use jar command to run the MapReduce program in the jar file
  • Output directory will be created automatically
hadoop jar MRWordCount.jar your_student_id.WordCountDriver /wordcount /wordcount_output
  • Structure of the command:
hadoop jar  <jar file>  <package>.<MainClass>  <input dir in HDFS>  <output dir in HDFS>
                                               └── args[0]          └── args[1]

  • Reading the log:
    • number of splits: 1 → 1 map task (file is smaller than one HDFS block of 128 MB)
    • map X% reduce Y% → progress; reducers start after maps finish
    • completed successfully + Counters → job done; counters show records read/written
  • ⚠️ If the output directory already exists, the job fails (FileAlreadyExistsException) → delete it first or use a new name:
hadoop fs -rm -r /wordcount_output

Check Result from CLI

CAPTURE SCREEN

  • Use cat command to view the output. Better to use ls first to check files
  • part-r-00000 is the output file. If the input file is very large, the output may have multiple files — equal to number of reducers
$HADOOP_HOME/bin/hadoop fs -ls /wordcount_output
$HADOOP_HOME/bin/hadoop fs -cat /wordcount_output/part-r-00000

Number of output files (part-r-*)=Number of reducers\boxed{\text{Number of output files } (\texttt{part-r-*}) = \text{Number of reducers}}
  • Output files:
    • _SUCCESS — empty marker file = the job finished successfully
    • part-r-00000, part-r-00001, ... — one per reducer (r = reducer output; m would be map-only output)
    • Each line = WORD<TAB>count
  • Notice punctuation stays attached ("AFTER, !)) because the mapper only splits on a space " "

Each reducer writes its own result sheet. 3 reducers → 3 sheets (part-r-00000..00002). Together they make the full answer; each word appears in exactly one of them.


Check Result File on HDFS

CAPTURE SCREEN

  • Access to HDFS GUI
  • Utilities ⇒ Browse the file system
  • Make sure to see URL in the capture

  • Columns: Permission, Owner, Group, Size, Last Modified, Replication, Block Size (128 MB), Name

Check MapReduce Process on YARN

  • Access to YARN GUI (http://<primary-dns>:8088)
  • Select your application: WordCounter (the name set by job.setJobName(...))

CAPTURE SCREEN

  • Click the application ID to see its details page

  • Key fields:
    • State = FINISHED, FinalStatus = SUCCEEDED → the job worked
    • Elapsed — total job time (e.g. 30 sec)
    • Logs link — debug output if something fails

Exercise

  • Create MapReduce Program to list of unique ID with total line count of each id
  • Use file: taxi.csv
  • Submit screen captures of the following steps:
    • Execute MapReduce
    • Check Result from CLI
    • Check MapReduce Process on YARN
  • Submit via Google Classroom Assignment

  • taxi.csv format (no header, comma-separated) — first column is the taxi ID:
5yc/f14Tqe9XCRu5qCGxv5qo+ug,1,13.83610,100.47647,2017-04-11 09:10:26,0,288,0,1
EO8d8iuEH3vjgNQURcvOM/PxgQo,1,13.82045,100.46629,2018-08-01 00:00:10,0,169,1,0
7D8GUsE79mc8lTjsrfnVPrxRgU0,0,13.72489,100.54439,2018-08-01 00:00:11,10,8,0,1
  • Idea: it is WordCount with a different key
    • Mapper: split each line by , → take column 0 (ID) → emit ⟨id,1⟩\langle id, 1 \rangle
    • Reducer: same sum logic as WordCountReducer
count(id)=number of lines in taxi.csv whose first column=id\boxed{\text{count}(id) = \text{number of lines in taxi.csv whose first column} = id}

Same recipe, different ingredient: instead of counting how many times each word appears in a book, you count how many GPS records each taxi has in a log file.


Done.


Summary — Full Command Cheat Sheet

# 1) On your Mac: connect to the primary node
cd ~/Downloads
chmod 400 labsuser.pem
scp -i labsuser.pem MRWordCount.jar book.txt taxi.csv hadoop@<primary-dns>:/home/hadoop/
ssh -i labsuser.pem hadoop@<primary-dns>
 
# 2) On the primary node: put data into HDFS
hadoop fs -mkdir /wordcount
hadoop fs -put /home/hadoop/book.txt /wordcount
hadoop fs -ls /wordcount
 
# 3) Run the job
hadoop jar MRWordCount.jar <your_package>.WordCountDriver /wordcount /wordcount_output
 
# 4) Check results
hadoop fs -ls /wordcount_output
hadoop fs -cat /wordcount_output/part-r-00000
 
# 5) Web UIs (open ports 9870 and 8088 for your IP first)
#   HDFS: http://<primary-dns>:9870   (Utilities → Browse the file system)
#   YARN: http://<primary-dns>:8088   (find app "WordCounter")
ItemValue
EMR releaseemr-7.9.0 (Hadoop 3.4.1)
Nodes1 Primary + 2 Core, m4.large, no Task
Idle auto-terminate3 hours
Key pairvockey (download labsuser.pem)
RolesEMR_DefaultRole, EMR_EC2_DefaultRole
SSH user / porthadoop / 22
HDFS UI port9870
YARN UI port8088
Java level1.8
Output files_SUCCESS + part-r-0000N (one per reducer)