我已经为我们的映射器编写了自定义 Recordreader,以便一次从源文件接收 3 条记录(3 行),而不是 TextInputFormat 默认提供的 1 行。以下是示例代码片段。
扩展 TextInputFormat:
public class NLinesInputFormat extends TextInputFormat{
@Override
public RecordReader<LongWritable, Text>; createRecordReader(InputSplit split, TaskAttemptContext context) {
return new NLinesRecordReader();
}
}
自定义 RecordReader 类
public class NLinesRecordReader extends RecordReader<LongWritable, Text>{
private final int NLINESTOPROCESS = 3;
private LineReader in;
private LongWritable key;
private Text value = new Text();
private long start =0;
private long end =0;
通过添加以下代码行修改驱动程序以使用新的输入格式
job.setInputFormatClass(NLinesInputFormat.class);
但是上面的行抛出了下面的错误
The method setInputFormatClass(Class<? extends InputFormat>) in the type Job is not applicable for the arguments (Class<NLinesInputFormat>)
我不确定是什么导致了这个错误。我没有混合使用任何新旧 API。我只使用新的 API。请帮助我。
最佳答案
您不需要编写自定义 NLineInpuFormat,它已经可用。
试试这个,
Configuration conf = new Configuration();
conf.setInt(
"mapreduce.input.lineinputformat.linespermap", 3);
Job job = new Job(conf, "word count");
job.setInputFormatClass(NLineInputFormat.class);
关于java - Mapreduce:NLineInputFormat 抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33560673/