hadoop 新手并试图理解来自 here 的 mapreduce wordcount 示例代码.
文档中的映射器是 -
Mapper<KEYIN,VALUEIN,KEYOUT,VALUEOUT>
我看到在mapreduce字数统计例子中map代码如下
public void map(Object key, Text value, Context context)
问题 - 这个对象类型的键有什么意义?如果映射器的输入是文本文档,我假设其中的值是 hadoop 已分区并存储在 HDFS 中的文本 block (64MB 或 128MB)。 更笼统地说,这个输入键输入 map 代码有什么用?
任何指点将不胜感激
最佳答案
InputFormat 描述了 Map-Reduce 作业的输入规范。默认情况下,hadoop 使用继承 FileInputFormat
的 TextInputFormat
来处理输入文件。
我们还可以指定在客户端或驱动程序代码中使用的输入格式:
job.setInputFormatClass(SomeInputFormat.class);
对于 TextInputFormat
,文件被分成多行。键是文件中的位置,值是文本行。
在 public void map(Object key, Text value, Context context)
中,key 是行偏移,< em>value 是实际的文本。
请查看 TextInputFormat API https://hadoop.apache.org/docs/current/api/org/apache/hadoop/mapreduce/lib/input/TextInputFormat.html
默认情况下,对于 TextInputFormat
,键是 LongWritable
类型,值是 Text
类型。在您的示例中,对象类型在LongWritable
的位置,因为它是兼容的。您还可以使用 LongWritable
类型代替 Object
关于java - hadoop映射器中对象类型的键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29063844/