Hadoop ecosystem overview - Time & Space Complexity
We want to understand how the time to process data grows as the data size increases in the Hadoop ecosystem.
How does Hadoop handle bigger data and what parts take more time?
Analyze the time complexity of a simple MapReduce job in Hadoop.
// Mapper class
public class MyMapper extends Mapper {
public void map(LongWritable key, Text value, Context context) {
// process each line of input
// emit key-value pairs
}
}
// Reducer class
public class MyReducer extends Reducer {
public void reduce(Text key, Iterable values, Context context) {
// sum values for each key
// emit final result
}
}
This code processes input data line by line, maps it to key-value pairs, then reduces by summing values per key.
Look at the loops and repeated steps in the MapReduce job.
- Primary operation: The mapper processes each input line once.
- How many times: Once per input line, so as many times as there are lines (n).
- Secondary operation: The reducer processes each unique key and sums its values.
- How many times: Once per unique key, which depends on data but usually less than n.
As the input data grows, the mapper runs more times, once per line.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | About 10 map operations |
| 100 | About 100 map operations |
| 1000 | About 1000 map operations |
Pattern observation: The number of operations grows roughly in direct proportion to the input size.
Time Complexity: O(n)
This means the time to run the job grows linearly with the amount of input data.
[X] Wrong: "The reducer runs as many times as the input lines."
[OK] Correct: The reducer runs once per unique key, which is usually fewer than input lines, so it does less work than the mapper.
Understanding how Hadoop scales with data size helps you explain real-world data processing and shows you can think about performance clearly.
"What if the reducer had to sort all keys before processing? How would the time complexity change?"
Practice
Solution
Step 1: Understand Hadoop storage components
Hadoop uses a distributed file system to store data across many machines.Step 2: Identify the storage system in Hadoop
HDFS (Hadoop Distributed File System) is designed for this purpose.Final Answer:
HDFS -> Option CQuick Check:
Storage = HDFS [OK]
- Confusing YARN with storage
- Thinking MapReduce stores data
- Mixing Hive with storage
Solution
Step 1: Recall Hadoop job submission syntax
The standard command to run a MapReduce job is 'hadoop jar'.Step 2: Match the correct command
hadoop jar myjob.jar input output uses 'hadoop jar' followed by the jar file and input/output paths.Final Answer:
hadoop jar myjob.jar input output -> Option AQuick Check:
Submit job = hadoop jar [OK]
- Using 'hadoop run' instead of 'jar'
- Confusing 'execute' with 'jar'
- Using 'start' which is invalid
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String line = value.toString();
for (String word : line.split(" ")) {
context.write(new Text(word), new IntWritable(1));
}
}Solution
Step 1: Analyze the map function logic
The code splits the input line into words and writes each word with value 1.Step 2: Determine output key-value pairs
Output keys are words; values are always 1.Final Answer:
Each word from the input line paired with the number 1 -> Option DQuick Check:
Map output = (word, 1) pairs [OK]
- Thinking output is whole line
- Using word length as key
- Using characters instead of words
data = LOAD 'input.txt' USING PigStorage(',') AS (name:chararray, age:int);
filtered = FILTER data BY age > 25;
DUMP filtered;Solution
Step 1: Check PigStorage usage
PigStorage supports comma delimiter, so PigStorage does not support comma as delimiter is incorrect.Step 2: Validate FILTER and DUMP syntax
FILTER and DUMP syntax are correct as per Pig Latin.Step 3: Consider common errors
Most errors come from wrong file paths or missing files.Final Answer:
The input file path is incorrect or missing -> Option AQuick Check:
File path error = The input file path is incorrect or missing [OK]
- Assuming delimiter unsupported
- Miswriting FILTER syntax
- Thinking DUMP is invalid
Solution
Step 1: Identify tools for SQL-like queries
Hive is designed to let users write SQL-like queries on Hadoop data.Step 2: Understand other tools' roles
HDFS stores data, YARN manages resources, MapReduce processes data but is not SQL-like.Final Answer:
Hive, because it provides SQL-like querying on Hadoop data -> Option BQuick Check:
SQL queries on Hadoop = Hive [OK]
- Confusing storage with querying
- Thinking YARN runs queries
- Assuming MapReduce is SQL-based
Ready to prove it?
Pass the test and this pattern moves unknown
