Reputation: 1352
New to hadoop and trying to understand the mapreduce wordcount example code from here.
The mapper from documentation is -
Mapper<KEYIN,VALUEIN,KEYOUT,VALUEOUT>
I see that in the mapreduce word count example the map code is as follows
public void map(Object key, Text value, Context context)
Question - What is the point of this key of type Object? If the input to a mapper is a text document I am assuming the value in would be the chunk of text (64MB or 128MB) that hadoop has partitioned and stored in HDFS. More generally, what is the use of this input key Keyin to the map code?
Any pointers would be greatly appreciated
Upvotes: 5
Views: 4043
Reputation:
InputFormat describes the input-specification for a Map-Reduce job.By default, hadoop uses TextInputFormat
, which inherits FileInputFormat
, to process the input files.
We can also specify the input format to use in the client or driver code:
job.setInputFormatClass(SomeInputFormat.class);
For the TextInputFormat
, files are broken into lines. Keys are the position in the file, and values are the line of text.
In the public void map(Object key, Text value, Context context)
, key is the line offset and value is the actual text.
Please look at TextInputFormat API https://hadoop.apache.org/docs/current/api/org/apache/hadoop/mapreduce/lib/input/TextInputFormat.html
By default, Key is LongWritable
type and value is of type Text
for the TextInputFormat
.In your example, Object type is specified in the place of LongWritable
as it is compatible. You can also use LongWritable
type in the place of Object
Upvotes: 8