Mapreduce:NLineInputFormat抛出错误

时间:2015-11-06 06:22:03

标签: java hadoop mapreduce

我已经为我们的映射器编写了Custom 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。我正在使用新的API。请帮帮我。

1 个答案:

答案 0 :(得分:0)

您不需要编写Custom NLineInpuFormat,它已经可用。

试试这个,

 Configuration conf = new Configuration();
    conf.setInt(
            "mapreduce.input.lineinputformat.linespermap", 3);
    Job job = new Job(conf, "word count");
    job.setInputFormatClass(NLineInputFormat.class);