手机版
你好,游客 登录 注册
背景:
阅读新闻

Hadoop streaming中指定自定义的inputformat java类

[日期:2012-04-02] 来源:Linux社区  作者:j3smile [字体:大 中 小]

解决了Hadoop streaming中指定自定义的inputformat java类

想在streaming中用自己的输入类:

看到网上说:

How do I provide my own input/output format with streaming?

At least as late as version 0.14, Hadoop does not support multiple jar files. So, when specifying your own custom classes you will have to pack them along with the streaming jar and use the custom jar instead of the default hadoop streaming jar.

也没找到其他的解决办法,就想到自己编译了

1)用grep TextInputFormat 方式找到stream的源码在: hadoop-0.20.2/src/contrib/streaming/src/java/org/apache/hadoop/streaming下:

查看StreamJob.java

  1. inputFormatSpec_ = (String)cmdLine.getOptionValue("inputformat");  

  1. if (inReaderSpec_ == null && inputFormatSpec_ == null) {  
  2.       fmt = TextInputFormat.class;  
  3.     } else if (inputFormatSpec_ != null) {  
  4.       if (inputFormatSpec_.equals(TextInputFormat.class.getName())  
  5.           || inputFormatSpec_.equals(TextInputFormat.class.getCanonicalName())  
  6.           || inputFormatSpec_.equals(TextInputFormat.class.getSimpleName())) {  
  7.         fmt = TextInputFormat.class;  
  8.       } else if (inputFormatSpec_.equals(KeyValueTextInputFormat.class  
  9.           .getName())  
  10.           || inputFormatSpec_.equals(KeyValueTextInputFormat.class  
  11.               .getCanonicalName())  
  12.           || inputFormatSpec_.equals(KeyValueTextInputFormat.class.getSimpleName())) {  
  13.       } else if (inputFormatSpec_.equals(SequenceFileInputFormat.class  
  14.           .getName())  
  15.           || inputFormatSpec_  
  16.               .equals(org.apache.hadoop.mapred.SequenceFileInputFormat.class  
  17.                   .getCanonicalName())  
  18.           || inputFormatSpec_  
  19.               .equals(org.apache.hadoop.mapred.SequenceFileInputFormat.class.getSimpleName())) {  
  20.       } else if (inputFormatSpec_.equals(SequenceFileAsTextInputFormat.class  
  21.           .getName())  
  22.           || inputFormatSpec_.equals(SequenceFileAsTextInputFormat.class  
  23.               .getCanonicalName())  
  24.           || inputFormatSpec_.equals(SequenceFileAsTextInputFormat.class.getSimpleName())) {  
  25.         fmt = SequenceFileAsTextInputFormat.class;  
  26.       } else {  
  27.         c = StreamUtil.goodClassOrNull(jobConf_, inputFormatSpec_, defaultPackage);  
  28.         if (c != null) {  
  29.           fmt = c;  
  30.         } else {  
  31.           fail("-inputformat : class not found : " + inputFormatSpec_);  
  32.         }  
  1. String defaultPackage = this.getClass().getPackage().getName();  
  1. package org.apache.hadoop.streaming;  

看到源码hadoop streaming会自动找包org.apache.hadoop.streaming的类做为inputformat类。

更多Hadoop相关信息见Hadoop 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=13
linux
本文评论   查看全部评论 (1)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款
第 1 楼
* lo2000 发表于 2012/4/2 23:05:11
您好
今天我想自己改寫OutputFormat並在streaming參數指定使用

javac -classpath /opt/hadoop/hadoop-core-0.20.203.0.jar:/opt/hadoop/lib/* /opt/hadoop/src/mapred/***/apache/hadoop/mapred/lib/MultipleOutputFormat.java -Xlint:deprecation

用jar uf 將class打包到原來的streaming
jar -uf contrib/streaming/hadoop-streaming-0.20.203.0.jar /opt/hadoop/src/mapred/***/apache/hadoop/mapred/lib/MultipleOutputFormat.class

執行時卻有-outputformat : class not found : MultipleOutputFormat 的錯誤
不知道是哪裡出了問題呢?
麻煩不吝指教 謝謝