File tree Expand file tree Collapse file tree 2 files changed +26
-1
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 +26
-1
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 @@ -898,6 +898,18 @@ class HiveQuerySuite extends HiveComparisonTest with BeforeAndAfter {
898
898
sql(" DROP TABLE t1" )
899
899
}
900
900
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
+
901
913
test(" ADD FILE command" ) {
902
914
val testFile = TestHive .getHiveFile(" data/files/v1.txt" ).getCanonicalFile
903
915
sql(s " ADD FILE $testFile" )
You can’t perform that action at this time.
0 commit comments