HIVE-10576 : add jar command does not work with Windows OS ( Hari Sankar 
Sivarama Subramaniyan via Thejas Nair)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/7276cd2a
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/7276cd2a
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/7276cd2a

Branch: refs/heads/beeline-cli
Commit: 7276cd2a563b3159e7bba0c1d74b2ec1b505913e
Parents: 92d0b81
Author: Thejas Nair <the...@hortonworks.com>
Authored: Tue May 5 12:27:57 2015 -0700
Committer: Thejas Nair <the...@hortonworks.com>
Committed: Tue May 5 12:27:57 2015 -0700

----------------------------------------------------------------------
 .../hadoop/hive/ql/session/SessionState.java    | 27 +++++++++++++++-----
 1 file changed, 21 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/7276cd2a/ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java 
b/ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java
index b531cc9..8db78e5 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java
@@ -84,6 +84,7 @@ import org.apache.hadoop.hive.shims.ShimLoader;
 import org.apache.hadoop.hive.shims.Utils;
 import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.hadoop.util.ReflectionUtils;
+import org.apache.hadoop.util.Shell;
 
 import com.google.common.base.Preconditions;
 
@@ -1160,7 +1161,7 @@ public class SessionState {
 
         if (getURLType(value).equals("ivy")) {
           // get the key to store in map
-          key = new URI(value).getAuthority();
+          key = createURI(value).getAuthority();
         } else {
           // for local file and hdfs, key and value are same.
           key = downloadedURLs.get(0).toString();
@@ -1201,8 +1202,22 @@ public class SessionState {
     return localized;
   }
 
+  /**
+   * @param path
+   * @return URI corresponding to the path.
+   */
+  private static URI createURI(String path) throws URISyntaxException {
+    if (!Shell.WINDOWS) {
+      // If this is not windows shell, path better follow unix convention.
+      // Else, the below call will throw an URISyntaxException
+      return new URI(path);
+    } else {
+      return new Path(path).toUri();
+    }
+  }
+
   private static String getURLType(String value) throws URISyntaxException {
-    URI uri = new URI(value);
+    URI uri = createURI(value);
     String scheme = uri.getScheme() == null ? null : 
uri.getScheme().toLowerCase();
     if (scheme == null || scheme.equals("file")) {
       return "file";
@@ -1215,13 +1230,13 @@ public class SessionState {
 
   List<URI> resolveAndDownload(ResourceType t, String value, boolean 
convertToUnix) throws URISyntaxException,
       IOException {
-    URI uri = new URI(value);
+    URI uri = createURI(value);
     if (getURLType(value).equals("file")) {
       return Arrays.asList(uri);
     } else if (getURLType(value).equals("ivy")) {
       return dependencyResolver.downloadDependencies(uri);
     } else if (getURLType(value).equals("hdfs")) {
-      return Arrays.asList(new URI(downloadResource(value, convertToUnix)));
+      return Arrays.asList(createURI(downloadResource(value, convertToUnix)));
     } else {
       throw new RuntimeException("Invalid url " + uri);
     }
@@ -1252,7 +1267,7 @@ public class SessionState {
         throw new RuntimeException("Couldn't create directory " + resourceDir);
       }
       try {
-        FileSystem fs = FileSystem.get(new URI(value), conf);
+        FileSystem fs = FileSystem.get(createURI(value), conf);
         fs.copyToLocalFile(new Path(value), new 
Path(destinationFile.getCanonicalPath()));
         value = destinationFile.getCanonicalPath();
 
@@ -1286,7 +1301,7 @@ public class SessionState {
       String key = value;
       try {
         if (getURLType(value).equals("ivy")) {
-          key = new URI(value).getAuthority();
+          key = createURI(value).getAuthority();
         }
       } catch (URISyntaxException e) {
         throw new RuntimeException("Invalid uri string " + value + ", " + 
e.getMessage());

Reply via email to