Repository: hive Updated Branches: refs/heads/master bdacb1052 -> ee3a3ed35
HIVE-16808 WebHCat statusdir parameter doesn't properly handle Unicode characters when using relative path (Eugene Koifman, reviewed by Daniel Dai, Peter Vary) Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/ee3a3ed3 Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/ee3a3ed3 Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/ee3a3ed3 Branch: refs/heads/master Commit: ee3a3ed35b337ff13156c6c6e27dd332cdee2009 Parents: bdacb10 Author: Eugene Koifman <ekoif...@hortonworks.com> Authored: Tue Jun 6 09:20:15 2017 -0700 Committer: Eugene Koifman <ekoif...@hortonworks.com> Committed: Tue Jun 6 09:20:15 2017 -0700 ---------------------------------------------------------------------- .../hcatalog/templeton/tool/TempletonUtils.java | 28 +++++++++----------- .../templeton/tool/TestTempletonUtils.java | 11 ++++---- 2 files changed, 19 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/ee3a3ed3/hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/TempletonUtils.java ---------------------------------------------------------------------- diff --git a/hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/TempletonUtils.java b/hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/TempletonUtils.java index e0ccc70..d3e801a 100644 --- a/hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/TempletonUtils.java +++ b/hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/TempletonUtils.java @@ -40,8 +40,6 @@ import java.util.StringTokenizer; import java.util.regex.Matcher; import java.util.regex.Pattern; -import javax.ws.rs.core.UriBuilder; - import org.apache.hadoop.hive.common.LogUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,10 +48,8 @@ import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.security.UserGroupInformation; -import org.apache.hadoop.util.Shell; import org.apache.hadoop.util.StringUtils; import org.apache.hive.hcatalog.templeton.UgiFactory; -import org.apache.hive.hcatalog.templeton.BadParam; /** * General utility methods. @@ -319,17 +315,19 @@ public class TempletonUtils { 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) http://git-wip-us.apache.org/repos/asf/hive/blob/ee3a3ed3/hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/tool/TestTempletonUtils.java ---------------------------------------------------------------------- diff --git a/hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/tool/TestTempletonUtils.java b/hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/tool/TestTempletonUtils.java index 3dcdd64..8328245 100644 --- a/hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/tool/TestTempletonUtils.java +++ b/hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/tool/TestTempletonUtils.java @@ -26,7 +26,6 @@ import java.io.IOException; 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 class TestTempletonUtils { 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 class TestTempletonUtils { TempletonUtils.addUserHomeDirectoryIfApplicable(badUri, "webhcat"); Assert.fail("addUserHomeDirectoryIfApplicable should fail for bad URI: " + badUri); - } catch (URISyntaxException ex) { + } catch (IllegalArgumentException ex) { } }