解决了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
- inputFormatSpec_ = (String)cmdLine.getOptionValue("inputformat");
- if (inReaderSpec_ == null && inputFormatSpec_ == null) {
- fmt = TextInputFormat.class;
- } else if (inputFormatSpec_ != null) {
- if (inputFormatSpec_.equals(TextInputFormat.class.getName())
- || inputFormatSpec_.equals(TextInputFormat.class.getCanonicalName())
- || inputFormatSpec_.equals(TextInputFormat.class.getSimpleName())) {
- fmt = TextInputFormat.class;
- } else if (inputFormatSpec_.equals(KeyValueTextInputFormat.class
- .getName())
- || inputFormatSpec_.equals(KeyValueTextInputFormat.class
- .getCanonicalName())
- || inputFormatSpec_.equals(KeyValueTextInputFormat.class.getSimpleName())) {
- } else if (inputFormatSpec_.equals(SequenceFileInputFormat.class
- .getName())
- || inputFormatSpec_
- .equals(org.apache.hadoop.mapred.SequenceFileInputFormat.class
- .getCanonicalName())
- || inputFormatSpec_
- .equals(org.apache.hadoop.mapred.SequenceFileInputFormat.class.getSimpleName())) {
- } else if (inputFormatSpec_.equals(SequenceFileAsTextInputFormat.class
- .getName())
- || inputFormatSpec_.equals(SequenceFileAsTextInputFormat.class
- .getCanonicalName())
- || inputFormatSpec_.equals(SequenceFileAsTextInputFormat.class.getSimpleName())) {
- fmt = SequenceFileAsTextInputFormat.class;
- } else {
- c = StreamUtil.goodClassOrNull(jobConf_, inputFormatSpec_, defaultPackage);
- if (c != null) {
- fmt = c;
- } else {
- fail("-inputformat : class not found : " + inputFormatSpec_);
- }
- String defaultPackage = this.getClass().getPackage().getName();
- package org.apache.hadoop.streaming;
看到源码hadoop streaming会自动找包org.apache.hadoop.streaming的类做为inputformat类。
更多Hadoop相关信息见Hadoop 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=13
