0
我写了一些Hadoop的代码读取映射文件,并将其分割成块,并把它写入许多文件如下:Hadoop的多路输出
public void map(LongWritable key, Text value, OutputCollector<IntWritable, Text>
output,Reporter reporter) throws IOException {
String line = value.toString();
int totalLines = 2000;
int lines = 0;
int fileNum = 1;
String[] linesinfile = line.split("\n");
while(lines<linesinfile.length) {
// I do something like, if lines = totalLines, {
output.collect(new IntWritable(fileNum), new
Text(linesinfile[lines].toString()));
fileNum++;
lines = 0;
}
lines++;
}
}
在降低,我做的:
public void reduce(IntWritable key, Iterator<Text> values,
OutputCollector<IntWritable, Text> output, Reporter reporter) throws IOException {
while(values.hasNext()){
output.collect(key, values.next());
}
}
我的多文件类如下:
public class MultiFileOutput extends MultipleTextOutputFormat<IntWritable, Text> {
protected String generateFileNameForKeyValue(IntWritable key, Text content, String
fileName) {
return key.toString() + "-" + fileName;
}
}
在主,我说:
conf.setInputFormat(TextInputFormat.class);
conf.setOutputFormat(MultiFileOutput.class);
除了设置OutKey /值类等
我在做什么错?我的输出目录始终为空。
谢谢
谢谢。其实我有一种误解,认为hadoop只会将输入文件的数量设置为许多映射器(我刚刚开始使用hadoop)。现在我已经将numMapTasks设置为5000。 – svk