Repository: spark
Updated Branches:
  refs/heads/branch-1.5 6e823b4d7 -> b478ee374


[SPARK-11595][SQL][BRANCH-1.5] Fixes ADD JAR when the input path contains URL 
scheme

This PR backports #9569 to branch-1.5.

Author: Cheng Lian <l...@databricks.com>

Closes #9570 from liancheng/spark-11595.for-branch-1.5.


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

Branch: refs/heads/branch-1.5
Commit: b478ee3743dd542004f2715e6d00eb999d1a06dd
Parents: 6e823b4
Author: Cheng Lian <l...@databricks.com>
Authored: Thu Nov 12 09:31:43 2015 -0800
Committer: Yin Huai <yh...@databricks.com>
Committed: Thu Nov 12 09:31:43 2015 -0800

----------------------------------------------------------------------
 .../apache/spark/sql/hive/execution/commands.scala   | 15 ++++++++++++++-
 .../spark/sql/hive/execution/SQLQuerySuite.scala     |  7 ++++++-
 2 files changed, 20 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/b478ee37/sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/commands.scala
----------------------------------------------------------------------
diff --git 
a/sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/commands.scala 
b/sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/commands.scala
index 9f654ee..1615803 100644
--- a/sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/commands.scala
+++ b/sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/commands.scala
@@ -17,6 +17,9 @@
 
 package org.apache.spark.sql.hive.execution
 
+import java.io.File
+
+import org.apache.hadoop.fs.Path
 import org.apache.hadoop.hive.metastore.MetaStoreUtils
 import org.apache.spark.sql._
 import org.apache.spark.sql.catalyst.{TableIdentifier, SqlParser}
@@ -90,7 +93,17 @@ case class AddJar(path: String) extends RunnableCommand {
     val currentClassLoader = Utils.getContextOrSparkClassLoader
 
     // Add jar to current context
-    val jarURL = new java.io.File(path).toURI.toURL
+    val jarURL = {
+      val uri = new Path(path).toUri
+      if (uri.getScheme == null) {
+        // `path` is a local file path without a URL scheme
+        new File(path).toURI.toURL
+      } else {
+        // `path` is a URL with a scheme
+        uri.toURL
+      }
+    }
+
     val newClassLoader = new java.net.URLClassLoader(Array(jarURL), 
currentClassLoader)
     Thread.currentThread.setContextClassLoader(newClassLoader)
     // We need to explicitly set the class loader associated with the conf in 
executionHive's

http://git-wip-us.apache.org/repos/asf/spark/blob/b478ee37/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
----------------------------------------------------------------------
diff --git 
a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
 
b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
index c98fddb..05504f1 100644
--- 
a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
+++ 
b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
@@ -70,7 +70,12 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils {
   private val sqlContext = _sqlContext
 
   test("UDTF") {
-    sql(s"ADD JAR ${TestHive.getHiveFile("TestUDTF.jar").getCanonicalPath()}")
+    val jarPath = TestHive.getHiveFile("TestUDTF.jar").getCanonicalPath
+
+    // SPARK-11595 Fixes ADD JAR when input path contains URL scheme
+    val jarURL = s"file://$jarPath"
+
+    sql(s"ADD JAR $jarURL")
     // The function source code can be found at:
     // https://cwiki.apache.org/confluence/display/Hive/DeveloperGuide+UDTF
     sql(


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org

Reply via email to