File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
main/scala/org/apache/spark/sql/hive/execution
test/scala/org/apache/spark/sql/hive/execution Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change 17
17
18
18
package org .apache .spark .sql .hive .execution
19
19
20
+ import java .io .File
21
+
22
+ import org .apache .hadoop .fs .Path
20
23
import org .apache .hadoop .hive .metastore .MetaStoreUtils
21
24
import org .apache .spark .sql ._
22
25
import org .apache .spark .sql .catalyst .{TableIdentifier , SqlParser }
@@ -90,7 +93,17 @@ case class AddJar(path: String) extends RunnableCommand {
90
93
val currentClassLoader = Utils .getContextOrSparkClassLoader
91
94
92
95
// 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
+
94
107
val newClassLoader = new java.net.URLClassLoader (Array (jarURL), currentClassLoader)
95
108
Thread .currentThread.setContextClassLoader(newClassLoader)
96
109
// We need to explicitly set the class loader associated with the conf in executionHive's
Original file line number Diff line number Diff line change @@ -70,7 +70,12 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils {
70
70
private val sqlContext = _sqlContext
71
71
72
72
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" )
74
79
// The function source code can be found at:
75
80
// https://cwiki.apache.org/confluence/display/Hive/DeveloperGuide+UDTF
76
81
sql(
You can’t perform that action at this time.
0 commit comments