diff --git hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/TempletonUtils.java hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/TempletonUtils.java index e0ccc70d52..2b48279731 100644 --- hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/TempletonUtils.java +++ hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/TempletonUtils.java @@ -36,6 +36,7 @@ import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.Random; import java.util.StringTokenizer; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -319,17 +320,19 @@ public static boolean hadoopFsIsMissing(FileSystem fs, Path p) { public static String addUserHomeDirectoryIfApplicable(String origPathStr, String user) throws IOException, URISyntaxException { - URI uri = new URI(origPathStr); - - if (uri.getPath().isEmpty()) { - String newPath = "/user/" + user; - uri = UriBuilder.fromUri(uri).replacePath(newPath).build(); - } else if (!new Path(uri.getPath()).isAbsolute()) { - String newPath = "/user/" + user + "/" + uri.getPath(); - uri = UriBuilder.fromUri(uri).replacePath(newPath).build(); - } // no work needed for absolute paths - - return uri.toString(); + if(origPathStr == null || origPathStr.isEmpty()) { + return "/user/" + user; + } + Path p = new Path(origPathStr); + if(p.isAbsolute()) { + return origPathStr; + } + if(p.toUri().getPath().isEmpty()) { + //origPathStr="hdfs://host:99" for example + return new Path(p.toUri().getScheme(), p.toUri().getAuthority(), "/user/" + user).toString(); + } + //can't have relative path if there is scheme/authority + return "/user/" + user + "/" + origPathStr; } public static Path hadoopFsPath(String fname, final Configuration conf, String user) diff --git hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/tool/TestTempletonUtils.java hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/tool/TestTempletonUtils.java index 3dcdd64844..8328245fac 100644 --- hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/tool/TestTempletonUtils.java +++ hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/tool/TestTempletonUtils.java @@ -26,7 +26,6 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.hive.shims.HadoopShimsSecure; -import org.apache.hadoop.hive.shims.ShimLoader; import org.apache.hadoop.util.StringUtils; import org.junit.After; import org.junit.Assert; @@ -271,18 +270,20 @@ public void testConstructingUserHomeDirectory() throws Exception { String[] sources = new String[] { "output+", "/user/hadoop/output", "hdfs://container", "hdfs://container/", "hdfs://container/path", "output#link", "hdfs://cointaner/output#link", - "hdfs://container@acc/test" }; + "hdfs://container@acc/test", "/user/webhcat/düsseldorf", "düsseldorf", + "䶴狝A﨩O", "hdfs://host:8080"}; String[] expectedResults = new String[] { "/user/webhcat/output+", "/user/hadoop/output", "hdfs://container/user/webhcat", "hdfs://container/", "hdfs://container/path", "/user/webhcat/output#link", "hdfs://cointaner/output#link", - "hdfs://container@acc/test" }; + "hdfs://container@acc/test", "/user/webhcat/düsseldorf","/user/webhcat/düsseldorf", + "/user/webhcat/䶴狝A﨩O", "hdfs://host:8080/user/webhcat" }; for (int i = 0; i < sources.length; i++) { String source = sources[i]; String expectedResult = expectedResults[i]; String result = TempletonUtils.addUserHomeDirectoryIfApplicable(source, "webhcat"); - Assert.assertEquals(result, expectedResult); + Assert.assertEquals("i=" + i, expectedResult, result); } String badUri = "c:\\some\\path"; @@ -290,7 +291,7 @@ public void testConstructingUserHomeDirectory() throws Exception { TempletonUtils.addUserHomeDirectoryIfApplicable(badUri, "webhcat"); Assert.fail("addUserHomeDirectoryIfApplicable should fail for bad URI: " + badUri); - } catch (URISyntaxException ex) { + } catch (IllegalArgumentException ex) { } }