You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mapreduce-commits@hadoop.apache.org by cd...@apache.org on 2010/03/05 23:18:49 UTC
svn commit: r919645 - in /hadoop/mapreduce/trunk: CHANGES.txt
src/java/org/apache/hadoop/mapreduce/lib/input/FileInputFormat.java
src/test/mapred/org/apache/hadoop/mapreduce/lib/input/TestFileInputFormat.java
Author: cdouglas
Date: Fri Mar 5 22:18:48 2010
New Revision: 919645
URL: http://svn.apache.org/viewvc?rev=919645&view=rev
Log:
MAPREDUCE-1522. FileInputFormat may use the default FileSystem for the
input path. Contributed by Tsz Wo (Nicholas), SZE
Added:
hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/mapreduce/lib/input/TestFileInputFormat.java
Modified:
hadoop/mapreduce/trunk/CHANGES.txt
hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapreduce/lib/input/FileInputFormat.java
Modified: hadoop/mapreduce/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/CHANGES.txt?rev=919645&r1=919644&r2=919645&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/CHANGES.txt (original)
+++ hadoop/mapreduce/trunk/CHANGES.txt Fri Mar 5 22:18:48 2010
@@ -1350,3 +1350,6 @@
cdouglas)
MAPREDUCE-1251. c++ utils doesn't compile. (Eli Collins via tomwhite)
+
+ MAPREDUCE-1522. FileInputFormat may use the default FileSystem for the
+ input path. (Tsz Wo (Nicholas), SZE via cdouglas)
Modified: hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapreduce/lib/input/FileInputFormat.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapreduce/lib/input/FileInputFormat.java?rev=919645&r1=919644&r2=919645&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapreduce/lib/input/FileInputFormat.java (original)
+++ hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapreduce/lib/input/FileInputFormat.java Fri Mar 5 22:18:48 2010
@@ -356,12 +356,11 @@
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(INPUT_DIR, str.toString());
@@ -377,8 +376,7 @@
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(INPUT_DIR);
conf.set(INPUT_DIR, dirs == null ? dirStr : dirs + "," + dirStr);
Added: hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/mapreduce/lib/input/TestFileInputFormat.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/mapreduce/lib/input/TestFileInputFormat.java?rev=919645&view=auto
==============================================================================
--- hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/mapreduce/lib/input/TestFileInputFormat.java (added)
+++ hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/mapreduce/lib/input/TestFileInputFormat.java Fri Mar 5 22:18:48 2010
@@ -0,0 +1,68 @@
+/**
+ * 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 org.junit.Test;
+import static org.junit.Assert.*;
+
+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 {
+
+ @Test
+ 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);
+ j.getConfiguration().set("fs.default.name", "s3://abc:xyz@hostname/");
+
+ //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]);
+ }
+ }
+
+}