我正在做一个 map reduce 工作,我想知道是否可以向我的输出文件发出自定义字符串。没有计数,没有其他数量,只是一团文本。
这是我所想的基本思想
public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
// this map doesn't do very much
String line = value.toString();
word.set(line);
// emit to map output
output.collect(word,one);
// but how to i do something like output.collect(word)
// because in my output file I want to control the text
// this is intended to be a map only job
}
}
这种事情可能吗?这是为了创建一个仅映射的作业来转换数据,使用 hadoop 的并行性,但不一定是整个 MR 框架。当我运行这个作业时,我会在 hdfs 中为每个映射器获得一个输出文件。
$ hadoop fs -ls /Users/dwilliams/output
2013-09-15 09:54:23.875 java[3902:1703] Unable to load realm info from SCDynamicStore
Found 12 items
-rw-r--r-- 1 dwilliams supergroup 0 2013-09-15 09:52 /Users/dwilliams/output/_SUCCESS
drwxr-xr-x - dwilliams supergroup 0 2013-09-15 09:52 /Users/dwilliams/output/_logs
-rw-r--r-- 1 dwilliams supergroup 7223469 2013-09-15 09:52 /Users/dwilliams/output/part-00000
-rw-r--r-- 1 dwilliams supergroup 7225393 2013-09-15 09:52 /Users/dwilliams/output/part-00001
-rw-r--r-- 1 dwilliams supergroup 7223560 2013-09-15 09:52 /Users/dwilliams/output/part-00002
-rw-r--r-- 1 dwilliams supergroup 7222830 2013-09-15 09:52 /Users/dwilliams/output/part-00003
-rw-r--r-- 1 dwilliams supergroup 7224602 2013-09-15 09:52 /Users/dwilliams/output/part-00004
-rw-r--r-- 1 dwilliams supergroup 7225045 2013-09-15 09:52 /Users/dwilliams/output/part-00005
-rw-r--r-- 1 dwilliams supergroup 7222759 2013-09-15 09:52 /Users/dwilliams/output/part-00006
-rw-r--r-- 1 dwilliams supergroup 7223617 2013-09-15 09:52 /Users/dwilliams/output/part-00007
-rw-r--r-- 1 dwilliams supergroup 7223181 2013-09-15 09:52 /Users/dwilliams/output/part-00008
-rw-r--r-- 1 dwilliams supergroup 7223078 2013-09-15 09:52 /Users/dwilliams/output/part-00009
如何在 1 个文件中获取结果?我应该使用身份缩减器吗?