我可以将Mapper的输入设置为hashMap而不是输入文件

时间:2013-06-08 03:04:35

标签: hadoop mapreduce mapper

我正在尝试设置一个利用dynamodb的并行扫描功能的MapReduce任务。

基本上,我希望每个Mapper类都将一个元组作为输入值。

到目前为止,我见过的每个例子都是这样的:

FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));

我可以将作业的输入格式设置为hashMap吗?

1 个答案:

答案 0 :(得分:0)

我认为您希望将文件读取为键值对,而不是读取inputSlipt的标准方式(行号作为键,行作为值)。如果它是你问的那么你可以使用 KeyValueTextInputFormat 下面的描述可以在Hadoop上找到:权威指南

KeyValueTextInputFormat
TextInputFormat’s keys, being simply the offset within the file, are not normally
very useful. It is common for each line in a file to be a key-value pair, 
separated by a delimiter such as a tab character. For example, this is the output   
produced by TextOutputFormat, Hadoop’s default OutputFormat. To interpret such 
files correctly, KeyValueTextInputFormat is appropriate.

You can specify the separator via the key.value.separator.in.input.line property. 
It is a tab character by default. Consider the following input file, 
where → represents a (horizontal) tab character:

line1→On the top of the Crumpetty Tree
line2→The Quangle Wangle sat,
line3→But his face you could not see,
line4→On account of his Beaver Hat.
Like in the TextInputFormat case, the input is in a single split comprising four
records, although this time the keys are the Text sequences before the tab in
each line:

(line1, On the top of the Crumpetty Tree)
(line2, The Quangle Wangle sat,)
(line3, But his face you could not see,)
(line4, On account of his Beaver Hat.)