Skip to content

Commit 8d06b98

Browse files
committed
Fixes SPARK-11595 for branch-1.5
1 parent 78a5cf1 commit 8d06b98

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
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/HiveQuerySuite.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,18 @@ class HiveQuerySuite extends HiveComparisonTest with BeforeAndAfter {
898898
sql("DROP TABLE t1")
899899
}
900900

901+
test("CREATE TEMPORARY FUNCTION") {
902+
val funcJar = TestHive.getHiveFile("TestUDTF.jar").getCanonicalPath
903+
val jarURL = s"file://$funcJar"
904+
sql(s"ADD JAR $jarURL")
905+
sql(
906+
"""CREATE TEMPORARY FUNCTION udtf_count2 AS
907+
|'org.apache.spark.sql.hive.execution.GenericUDTFCount2'
908+
""".stripMargin)
909+
assert(sql("DESCRIBE FUNCTION udtf_count2").count > 1)
910+
sql("DROP TEMPORARY FUNCTION udtf_count2")
911+
}
912+
901913
test("ADD FILE command") {
902914
val testFile = TestHive.getHiveFile("data/files/v1.txt").getCanonicalFile
903915
sql(s"ADD FILE $testFile")

0 commit comments

Comments
 (0)