You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by om...@apache.org on 2011/03/04 05:02:19 UTC

svn commit: r1077311 - in /hadoop/common/branches/branch-0.20-security-patches/src: mapred/org/apache/hadoop/mapreduce/lib/input/ test/org/apache/hadoop/mapreduce/lib/input/

Author: omalley
Date: Fri Mar  4 04:02:19 2011
New Revision: 1077311

URL: http://svn.apache.org/viewvc?rev=1077311&view=rev
Log:
commit a0fd6fc42205e9c56f10914731e508dd9d55911d
Author: Chris Douglas <cd...@apache.org>
Date:   Thu Mar 11 10:48:27 2010 -0800

    MAPREDUCE:1522 from https://issues.apache.org/jira/secure/attachment/12437994/M1522-1v20.patch
    
    +++ b/YAHOO-CHANGES.txt
    +    MAPREDUCE-1522. FileInputFormat may use the default FileSystem for the
    +    input path. (Tsz Wo (Nicholas), SZE via cdouglas)
    +

Added:
    hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/mapreduce/lib/input/
    hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/mapreduce/lib/input/TestFileInputFormat.java
Modified:
    hadoop/common/branches/branch-0.20-security-patches/src/mapred/org/apache/hadoop/mapreduce/lib/input/FileInputFormat.java

Modified: hadoop/common/branches/branch-0.20-security-patches/src/mapred/org/apache/hadoop/mapreduce/lib/input/FileInputFormat.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/mapred/org/apache/hadoop/mapreduce/lib/input/FileInputFormat.java?rev=1077311&r1=1077310&r2=1077311&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/mapred/org/apache/hadoop/mapreduce/lib/input/FileInputFormat.java (original)
+++ hadoop/common/branches/branch-0.20-security-patches/src/mapred/org/apache/hadoop/mapreduce/lib/input/FileInputFormat.java Fri Mar  4 04:02:19 2011
@@ -348,12 +348,11 @@ public abstract class FileInputFormat<K,
   public static void setInputPaths(Job job, 
                                    Path... inputPaths) throws IOException {
     Configuration conf = job.getConfiguration();
-    FileSystem fs = FileSystem.get(conf);
-    Path path = inputPaths[0].makeQualified(fs);
+    Path path = inputPaths[0].getFileSystem(conf).makeQualified(inputPaths[0]);
     StringBuffer str = new StringBuffer(StringUtils.escapeString(path.toString()));
     for(int i = 1; i < inputPaths.length;i++) {
       str.append(StringUtils.COMMA_STR);
-      path = inputPaths[i].makeQualified(fs);
+      path = inputPaths[i].getFileSystem(conf).makeQualified(inputPaths[i]);
       str.append(StringUtils.escapeString(path.toString()));
     }
     conf.set("mapred.input.dir", str.toString());
@@ -369,8 +368,7 @@ public abstract class FileInputFormat<K,
   public static void addInputPath(Job job, 
                                   Path path) throws IOException {
     Configuration conf = job.getConfiguration();
-    FileSystem fs = FileSystem.get(conf);
-    path = path.makeQualified(fs);
+    path = path.getFileSystem(conf).makeQualified(path);
     String dirStr = StringUtils.escapeString(path.toString());
     String dirs = conf.get("mapred.input.dir");
     conf.set("mapred.input.dir", dirs == null ? dirStr : dirs + "," + dirStr);

Added: hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/mapreduce/lib/input/TestFileInputFormat.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/mapreduce/lib/input/TestFileInputFormat.java?rev=1077311&view=auto
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/mapreduce/lib/input/TestFileInputFormat.java (added)
+++ hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/mapreduce/lib/input/TestFileInputFormat.java Fri Mar  4 04:02:19 2011
@@ -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.mapreduce.lib.input;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapreduce.Job;
+
+public class TestFileInputFormat extends TestCase {
+
+  public void testAddInputPath() throws IOException {
+    final Configuration conf = new Configuration();
+    conf.set("fs.default.name", "s3://abc:xyz@hostname/");
+    final Job j = new Job(conf);
+
+    //setup default fs
+    final FileSystem defaultfs = FileSystem.get(conf);
+    System.out.println("defaultfs.getUri() = " + defaultfs.getUri());
+
+    {
+      //test addInputPath
+      final Path original = new Path("file:/foo");
+      System.out.println("original = " + original);
+      FileInputFormat.addInputPath(j, original);
+      final Path[] results = FileInputFormat.getInputPaths(j);
+      System.out.println("results = " + Arrays.asList(results));
+      assertEquals(1, results.length);
+      assertEquals(original, results[0]);
+    }
+
+    {
+      //test setInputPaths
+      final Path original = new Path("file:/bar");
+      System.out.println("original = " + original);
+      FileInputFormat.setInputPaths(j, original);
+      final Path[] results = FileInputFormat.getInputPaths(j);
+      System.out.println("results = " + Arrays.asList(results));
+      assertEquals(1, results.length);
+      assertEquals(original, results[0]);
+    }
+  }
+
+}