From 9a6da7979ee035b2241c81c48ac4a4ba1e0aee48 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 7 Nov 2011 20:13:00 +0000 Subject: [PATCH] MAPREDUCE-3344. o.a.h.mapreduce.Reducer since 0.21 blindly casts to ReduceContext.ValueIterator. Contributed by Brock Noland. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1198910 13f79535-47bb-0310-9956-ffa450edef68 --- .../main/java/org/apache/hadoop/mapreduce/Reducer.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/Reducer.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/Reducer.java index bc7ad976f3..efb0950715 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/Reducer.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/Reducer.java @@ -26,6 +26,8 @@ import org.apache.hadoop.io.RawComparator; import org.apache.hadoop.mapred.RawKeyValueIterator; +import java.util.Iterator; + /** * Reduces a set of intermediate values which share a key to a smaller set of * values. @@ -162,14 +164,15 @@ protected void cleanup(Context context * {@link #run(org.apache.hadoop.mapreduce.Reducer.Context)} method to * control how the reduce task works. */ - @SuppressWarnings("unchecked") public void run(Context context) throws IOException, InterruptedException { setup(context); while (context.nextKey()) { reduce(context.getCurrentKey(), context.getValues(), context); // If a back up store is used, reset it - ((ReduceContext.ValueIterator) - (context.getValues().iterator())).resetBackupStore(); + Iterator iter = context.getValues().iterator(); + if(iter instanceof ReduceContext.ValueIterator) { + ((ReduceContext.ValueIterator)iter).resetBackupStore(); + } } cleanup(context); }