spark_dream
spark_dream

Reputation: 346

Mapper and Reducer are interfaces in Hadoop version 2?

Just a basic question.I know the Mapper and the Reducer are Interfaces in the Hadoop version 2. But still when coding I see examples using extends mapper or extends reducer instead of implements.Is there a reason for this or are they being implemented as in the old version due to backward compatibility? Here is the link where I've been studying https://hadoop.apache.org/docs/current/hadoop-mapreduce-client/hadoop-mapreduce-client-core/MapReduceTutorial.html#MapReduce_-_User_Interfaces

Upvotes: 0

Views: 625

Answers (3)

prasanth
prasanth

Reputation: 41

Yes -Mapper and Reducer were classes in HADOOP-1x and it has been enhanced to INTERFACE in later HADOOP -2x versions

EXAMPLE -CODE:

In previous versions of HADOOP

public static class New_Map extends MapReduceBase implements Mapper{

In HADOOP-2x

public static class New_Map extends Mapper{

Upvotes: 0

spark_dream
spark_dream

Reputation: 346

I found this when having a closer look at the APIs. org.apache.hadoop.mapreduce Class Reducer is for Hadoop2 where Mapper and the Reducer are Classes and org.apache.hadoop.mapred Interface Reducer was there in Hadoop 1 where they were interfaces which compiles in Hadoop 2 as well. It's just the difference between the old API and the new one that supports backward compatibility

Upvotes: 0

OneCricketeer
OneCricketeer

Reputation: 191681

Not sure where you are reading on that page that the Mapper and Reducer are interfaces for MapReduce2, but the source code on that page clearly uses classes. Keyword being extends.

import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
...
public static class TokenizerMapper extends Mapper
...
public static class IntSumReducer extends Reducer

It should be mentioned that the org.apache.hadoop.mapred.Mapper and org.apache.hadoop.mapred.Reducer are interfaces, but those are meant to be used for MapReduce1.

I think the purpose of re-writing the Mapper and Reducer as classes was to simplify class creation without using extends MapReduceBase implements like so

class MyReducer<K extends WritableComparable, V extends Writable> 
     extends MapReduceBase implements Reducer<K, V, K, V> 

Upvotes: 1

Related Questions