Skip to content

Commit b478ee3

Browse files
lianchengyhuai
authored andcommitted
[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 <lian@databricks.com> Closes #9570 from liancheng/spark-11595.for-branch-1.5.
1 parent 6e823b4 commit b478ee3

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/commands.scala

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
package org.apache.spark.sql.hive.execution
1919

20+
import java.io.File
21+
22+
import org.apache.hadoop.fs.Path
2023
import org.apache.hadoop.hive.metastore.MetaStoreUtils
2124
import org.apache.spark.sql._
2225
import org.apache.spark.sql.catalyst.{TableIdentifier, SqlParser}
@@ -90,7 +93,17 @@ case class AddJar(path: String) extends RunnableCommand {
9093
val currentClassLoader = Utils.getContextOrSparkClassLoader
9194

9295
// Add jar to current context
93-
val jarURL = new java.io.File(path).toURI.toURL
96+
val jarURL = {
97+
val uri = new Path(path).toUri
98+
if (uri.getScheme == null) {
99+
// `path` is a local file path without a URL scheme
100+
new File(path).toURI.toURL
101+
} else {
102+
// `path` is a URL with a scheme
103+
uri.toURL
104+
}
105+
}
106+
94107
val newClassLoader = new java.net.URLClassLoader(Array(jarURL), currentClassLoader)
95108
Thread.currentThread.setContextClassLoader(newClassLoader)
96109
// We need to explicitly set the class loader associated with the conf in executionHive's

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils {
7070
private val sqlContext = _sqlContext
7171

7272
test("UDTF") {
73-
sql(s"ADD JAR ${TestHive.getHiveFile("TestUDTF.jar").getCanonicalPath()}")
73+
val jarPath = TestHive.getHiveFile("TestUDTF.jar").getCanonicalPath
74+
75+
// SPARK-11595 Fixes ADD JAR when input path contains URL scheme
76+
val jarURL = s"file://$jarPath"
77+
78+
sql(s"ADD JAR $jarURL")
7479
// The function source code can be found at:
7580
// https://cwiki.apache.org/confluence/display/Hive/DeveloperGuide+UDTF
7681
sql(

0 commit comments

Comments
 (0)