MapReduce - Exam Hints Cheat Sheet
Here are high-yield, condensed cheat-sheet blocks addressing your professor’s specific exam hints (MapReduce Pseudocode, AWS EMR, and Data Cleaning Strategies).
1. MapReduce Pseudocode & Logic
- Map Phase: Reads
(Line_Number, Text_Line)splits string cleans tokens outputs key-value pairemit(key, value). - Reduce Phase: Takes
(key, list_of_values)loops/aggregates values outputs final pairemit(key, aggregated_result). - Word Count Example:
- Mapper:
map(doc_id, text): for word in text.split(): emit(word.lower(), 1) - Reducer:
reduce(word, counts): emit(word, sum(counts))
- Mapper:
- Inverted Index Example:
- Mapper:
map(doc_id, text): for word in text.split(): emit(word, doc_id) - Reducer:
reduce(word, doc_ids): emit(word, unique(doc_ids))
- Mapper:
- Optional Driver/Combiner:
- Combiner: Mini-reducer on the Mapper node to reduce network shuffle traffic.
- Partitioner: Routes
(key, value)to specific Reducers usinghash(key) % num_reducers.
2. AWS EMR Architecture & Components
- Master Node: Manages cluster state, coordinates task distribution, runs Resource Manager (YARN) and NameNode (HDFS).
- Core Node: Runs DataNode (HDFS) and NodeManager (YARN); handles processing AND stores persistent cluster data.
- Task Node: Only runs processing (YARN NodeManager); no HDFS storage. Good for auto-scaling spot instances.
- EMR vs. Self-Managed Hadoop: Elastic/auto-scaling, decoupled storage (S3 using EMRFS) and compute, automated provisioning.
- Ephemeral Cluster: Spin up EMR process data from S3 write results to S3 terminate cluster to save costs.
3. Data Quality & Cleaning (Handling "Dirty Data")
-
Syntax / Format Errors (Missing Commas, Quotes, Bad Delimiters):
-
Identification: Parsing failures, mismatched column counts, trailing spaces.
-
Fix: Use regex/string parsing, escape characters, or strip whitespace before splitting lines.
-
Missing Values:
-
Categorical: Replace with Mode or
"Unknown". -
Numerical: Replace with Mean/Median (Imputation) or drop row if missing rate is .
-
Outliers & Invalid Values:
-
Identification: Range checks (e.g., , ), IQR rule (, ), or Z-score ().
-
Fix: Cap values (winsorization), convert to NULL and impute, or filter out completely.
-
Duplicates & Inconsistencies:
-
Identification: Mismatched casing (
"NYC"vs"new york"), duplicated primary keys. -
Fix: Case normalization (
lower()), standardizing formats (dates toYYYY-MM-DD), and deduplication (DISTINCT/ grouping).
4. Extra Exam-Room Reminders (Quick Cheat-Sheet Wins)
-
Schema-on-Write vs Schema-on-Read: Data Warehouse enforces structure during ingest; Data Lake enforces structure when querying.
-
Data Verification vs Validation:
-
Validation: Checking structure, ranges, data types during/after import (Automated).
-
Verification: Ensuring accuracy against the real-world truth (e.g., manual check, two-pass entry).
-
Hadoop / YARN Terms:
-
NameNode: Master metadata storage.
-
DataNode: Block storage on local disks.
-
ResourceManager: Allocates cluster compute resources.
-
NodeManager: Executes compute containers on worker nodes.