开发者

Custom MapReduce Input Format - Can't Find Constructor

开发者 https://www.devze.com 2023-03-30 12:51 出处:网络
I\'m writing a custom InputFormat for Hadoop 0.20.2 and am running into a NoSuchMethodException I can\'t get rid of.I started with:

I'm writing a custom InputFormat for Hadoop 0.20.2 and am running into a NoSuchMethodException I can't get rid of. I started with:

public class ConnectionInputFormat extends FileInputFormat<Text, Connection> {

    @Override
    public RecordReader<Text, Connection> createRecordReader(InputSplit split, TaskAttemptContext context) throws IOException, InterruptedException {
        return new ConnectionRecordReader();
    }
}

I got this error when running:

Exception in thread "main" java.lang.RuntimeException: java.lang.NoSuchMethodException: testingground.TestInputJob$ConnectionInputFormat.<init>()
at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:115)
at org.apache.hadoop.mapred.JobClient.writeNewSplits(JobClient.java:882)
at org.apache.hadoop.mapred.JobClient.submitJobInternal(JobClient.java:779)
at org.apache.hadoop.mapreduce.Job.submit(Job.java:432)
at org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:447)
at testingground.TestInputJob.run(TestInputJob.java:141)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:65)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:79)
at testingground.TestInputJob.main(TestInputJob.java:156)
Caused by: java.lang.NoSuchMethodException: testingground.TestInputJob$ConnectionInputFormat.<init>()
at java.lang.Class.getConstructor0(Class.java:2706)
at java.lang.Class.getDeclaredConstructor(Class.java:1985)
at org.apache.hadoop.util.Reflec开发者_JAVA技巧tionUtils.newInstance(ReflectionUtils.java:109)
... 8 more
Java Result: 1

After getting the error inititially and researching online, I thought it might be that I didn't have a zero-argument constructor, so I added one:

public class ConnectionInputFormat extends FileInputFormat<Text, Connection> {

    public ConnectionInputFormat() {
        System.out.println("NetflowInputFormat Constructor");
    }

    @Override
    public RecordReader<Text, Connection> createRecordReader(InputSplit split, TaskAttemptContext context) throws IOException, InterruptedException {
        return new ConnectionRecordReader();
    }
}

That didn't work either, so I added a second constructor that took in any number of objects:

public class ConnectionInputFormat extends FileInputFormat<Text, Connection> {

    public ConnectionInputFormat() {
        System.out.println("NetflowInputFormat Constructor");
    }

    public ConnectionInputFormat(Object... o) {
        System.out.println("NetflowInputFormat Constructor");
    }

    @Override
    public RecordReader<Text, Connection> createRecordReader(InputSplit split, TaskAttemptContext context) throws IOException, InterruptedException {
        return new ConnectionRecordReader();
    }
}

Still getting the same error, and have been so far unsuccessful in finding a solution.

Full current source: http://pastebin.com/2XyW5ZSS


Your ConnectionInputFormat class should be static. Non-static nested classes have an implied 'this' added to every constructor. Thus, your no-arg constructor actually has an invisible argument unless the class is declared static.

0

精彩评论

暂无评论...
验证码 换一张
取 消