Просмотр исходного кода

HADOOP-5252. Streaming overrides -inputformat option. Contributed by Klaas Bosteels.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@778289 13f79535-47bb-0310-9956-ffa450edef68
Sharad Agarwal 16 лет назад
Родитель
Сommit
7c3c932486

+ 3 - 0
CHANGES.txt

@@ -670,6 +670,9 @@ Trunk (unreleased changes)
 
     HADOOP-5847. Fixed failing Streaming unit tests (gkesavan) 
 
+    HADOOP-5252. Streaming overrides -inputformat option (Klaas Bosteels 
+    via sharad)
+
 Release 0.20.1 - Unreleased
 
   INCOMPATIBLE CHANGES

+ 6 - 0
src/contrib/streaming/src/java/org/apache/hadoop/streaming/StreamJob.java

@@ -727,6 +727,9 @@ public class StreamJob implements Tool {
           || inputFormatSpec_.equals(KeyValueTextInputFormat.class
               .getCanonicalName())
           || inputFormatSpec_.equals(KeyValueTextInputFormat.class.getSimpleName())) {
+        if (inReaderSpec_ == null) {
+          fmt = KeyValueTextInputFormat.class;
+        }
       } else if (inputFormatSpec_.equals(SequenceFileInputFormat.class
           .getName())
           || inputFormatSpec_
@@ -734,6 +737,9 @@ public class StreamJob implements Tool {
                   .getCanonicalName())
           || inputFormatSpec_
               .equals(org.apache.hadoop.mapred.SequenceFileInputFormat.class.getSimpleName())) {
+        if (inReaderSpec_ == null) {
+          fmt = SequenceFileInputFormat.class;
+        }
       } else if (inputFormatSpec_.equals(SequenceFileAsTextInputFormat.class
           .getName())
           || inputFormatSpec_.equals(SequenceFileAsTextInputFormat.class

+ 65 - 0
src/contrib/streaming/src/test/org/apache/hadoop/streaming/TestStreamJob.java

@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.streaming;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.KeyValueTextInputFormat;
+import org.apache.hadoop.mapred.SequenceFileInputFormat;
+
+import junit.framework.TestCase;
+
+/**
+ * This class tests hadoop Streaming's StreamJob class.
+ */
+public class TestStreamJob extends TestCase {
+
+  public void testCreateJob() throws IOException {
+    JobConf job;
+    ArrayList<String> dummyArgs = new ArrayList<String>();
+    dummyArgs.add("-input"); dummyArgs.add("dummy");
+    dummyArgs.add("-output"); dummyArgs.add("dummy");
+    dummyArgs.add("-mapper"); dummyArgs.add("dummy");
+    dummyArgs.add("-reducer"); dummyArgs.add("dummy");
+    ArrayList<String> args;
+    
+    args = new ArrayList<String>(dummyArgs);
+    args.add("-inputformat");
+    args.add("org.apache.hadoop.mapred.KeyValueTextInputFormat");
+    job = StreamJob.createJob(args.toArray(new String[] {}));
+    assertEquals(KeyValueTextInputFormat.class, job.getInputFormat().getClass());
+    
+    args = new ArrayList<String>(dummyArgs);
+    args.add("-inputformat");
+    args.add("org.apache.hadoop.mapred.SequenceFileInputFormat");
+    job = StreamJob.createJob(args.toArray(new String[] {}));
+    assertEquals(SequenceFileInputFormat.class, job.getInputFormat().getClass());
+    
+    args = new ArrayList<String>(dummyArgs);
+    args.add("-inputformat");
+    args.add("org.apache.hadoop.mapred.KeyValueTextInputFormat");
+    args.add("-inputreader");
+    args.add("StreamXmlRecordReader,begin=<doc>,end=</doc>");
+    job = StreamJob.createJob(args.toArray(new String[] {}));
+    assertEquals(StreamInputFormat.class, job.getInputFormat().getClass());
+  }
+  
+}