自定义 MapReduce 输入格式 - 找不到构造函数

发布于 2024-11-30 15:18:17 字数 2743 浏览 1 评论 0原文

我正在为 Hadoop 0.20.2 编写一个自定义 InputFormat,但遇到了无法摆脱的 NoSuchMethodException。我一开始是:

public class ConnectionInputFormat extends FileInputFormat<Text, Connection> {

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

运行时出现此错误:

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.ReflectionUtils.newInstance(ReflectionUtils.java:109)
... 8 more
Java Result: 1

在最初收到错误并在线研究后,我认为可能是我没有零参数构造函数,所以我添加了一个:

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();
    }
}

这也不起作用,所以我添加了第二个构造函数,它接受任意数量的对象:

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();
    }
}

仍然遇到相同的错误,并且到目前为止尚未成功找到解决方案。

当前完整源代码:http://pastebin.com/2XyW5ZSS

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.ReflectionUtils.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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风吹雨成花 2024-12-07 15:18:17

您的 ConnectionInputFormat 类应该是静态的。非静态嵌套类在每个构造函数中添加了隐含的“this”。因此,您的无参数构造函数实际上有一个不可见的参数,除非该类被声明为静态。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文