Hint: Reduce gets key and list of values, not single value [OK]
Common Mistakes:
Confusing map and reduce method signatures
Using single VALUE instead of Iterable<VALUE> in reduce
Mixing map parameters with reduce function
3.
Given the following Reduce function snippet, what will be the output for key = "apple" and values = [2, 3, 5]?
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
int sum = 0;
for (IntWritable val : values) {
sum += val.get();
}
context.write(key, new IntWritable(sum));
}
medium
A. (apple, 2)
B. (apple, 10)
C. (apple, 0)
D. (apple, 5)
Solution
Step 1: Sum the values list
Values are 2, 3, and 5. Summing gives 2 + 3 + 5 = 10.
Step 2: Output key with summed value
The context writes the key "apple" with the sum 10 as IntWritable.
Final Answer:
(apple, 10) -> Option B
Quick Check:
Sum of values = 10 [OK]
Hint: Add all values for key to get output [OK]
Common Mistakes:
Returning only first value instead of sum
Returning count instead of sum
Ignoring values and outputting zero
4.
Identify the error in this Reduce function code snippet:
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
int sum = 0;
for (IntWritable val : values) {
sum = val.get();
}
context.write(key, new IntWritable(sum));
}
medium
A. The Iterable<IntWritable> should be a List<IntWritable>
B. The key parameter type is incorrect
C. The context.write method is missing
D. The sum variable is overwritten instead of accumulated
Solution
Step 1: Analyze the for loop logic
The code assigns sum = val.get() inside the loop, overwriting sum each time.
Step 2: Identify correct accumulation
Sum should accumulate values using sum += val.get() to add all values.
Final Answer:
The sum variable is overwritten instead of accumulated -> Option D
Quick Check:
Use += to accumulate sum, not = [OK]
Hint: Use += to add values, not = which overwrites [OK]
Common Mistakes:
Using = instead of += in accumulation
Confusing key type with error
Thinking context.write is missing
5.
You want to count the total occurrences of each word in a large text dataset using Hadoop MapReduce. Which of the following best describes what the Reduce phase should do?
hard
A. Receive each word as key and list of counts as values, then sum counts to get total occurrences
B. Split the input text into words and assign counts
C. Sort all words alphabetically before counting
D. Write the raw text data to output without changes
Solution
Step 1: Understand MapReduce word count flow
Map phase outputs (word, 1) pairs for each word occurrence.
Step 2: Role of Reduce phase in counting
Reduce receives each word as key and list of counts (1s), sums them to get total count.
Final Answer:
Receive each word as key and list of counts as values, then sum counts to get total occurrences -> Option A
Quick Check:
Reduce sums counts per word [OK]
Hint: Reduce sums counts for each word key [OK]
Common Mistakes:
Confusing Map and Reduce roles
Thinking Reduce sorts data
Assuming Reduce outputs raw data
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.