【问题标题】:How to bundle custom hadoop-streaming.jar如何捆绑自定义 hadoop-streaming.jar
【发布时间】:2013-01-11 20:33:24
【问题描述】:

我正在尝试使用 CombineFileInputFormat 类,使用 Yelp 的 MrJob 工具进行 EMR。作业流是使用 hadoop 流创建的,MrJob 的文档表明 CombineFileInputFormat 类必须捆绑在自定义的 hadoop-streaming.jar 中。

有关上下文,请关注此question

我的具体问题是:具体类CombinedInputFormat.class 应该在hadoop-streaming.jar 中捆绑或引用到哪里?

我尝试通过将CombinedInputFormat.class 添加到目录org/apache/hadoop/streaming 并执行来捆绑CombinedInputFormat.class

jar uvf my-hadoop-streaming.jar org/apache/hadoop/streaming

如果我这样做,流式作业流程将启动,选项 -inputformat CombinedInputFormat 作业开始第一步并中断,出现错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/streaming/CombinedInputFormat (wrong name: CombinedInputFormat)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
        ...

如果我只是尝试将其设置在根路径中:

jar uvf my-hadoop-streaming.jar CombinedInputFormat.class

我得到的错误是:

-inputformat : class not found : CombinedInputFormat
Streaming Job Failed!

我应该如何捆绑 CombinedInputFormat.class 以便正确获取并解决 NoClassDefFoundError 错误?

【问题讨论】:

    标签: java hadoop streaming mrjob


    【解决方案1】:

    CombinedInputFormat 类解释了 here 扩展 CombineFileInputFormat 并且没有移植到 hadoop。因此,您需要做的是,在您拥有映射器/减速器作业类的同一个包中,您必须创建一个类并拥有上一期中所述的代码。然后创建jar,它应该可以正常运行了。

    所以基本上,您需要编写自己的 CombineFileInputFormat 实现(我已经为您完成了),并且您可以将其命名为任何您想要的名称,例如 ABCClass 而不是我命名的 CombinedInputFormat

    【讨论】:

    • 感谢 Amar,我发现类未找到错误是由于自定义类模块开头没有 package 语句引起的。我有这个工作,但还有一个问题,这非常适合阅读原始文本行,但我在尝试使用 KeyValueLineRecordReader 实现一个类时遇到了麻烦。具体来说,我遇到了 next() 方法的问题,它似乎需要类型为(Object,Object)的参数,但是编译器在返回行上抱怨说它需要返回类型(Text,Text)。是什么导致了这个悖论?
    • 好的,所以您需要具体说明您在此处引用的泛型类型。也许您正在创建的课程类似于:MyClass extends KeyValueLineRecordReader,但您应该执行以下操作:MyClass extends KeyValueLineRecordReader<Text,Text>
    • 是的,事实上我昨晚意识到是这样,修复后它运行顺利。非常感谢您的帮助!
    【解决方案2】:

    这是我发现在 hadoop local 或 EMR 中构建和运行自定义 jar 的另一种简单方法 http://www.applams.com/2014/05/using-custom-streaming-jar-using-custom.html

    【讨论】:

      猜你喜欢
      • 2012-04-30
      • 1970-01-01
      • 1970-01-01
      • 2016-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-23
      • 1970-01-01
      相关资源
      最近更新 更多