File tree Expand file tree Collapse file tree
main/scala/org/apache/spark/sql/hive/execution
test/scala/org/apache/spark/sql/hive/execution Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717
1818package org .apache .spark .sql .hive .execution
1919
20+ import java .io .File
21+
22+ import org .apache .hadoop .fs .Path
2023import org .apache .hadoop .hive .metastore .MetaStoreUtils
2124import org .apache .spark .sql ._
2225import 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
Original file line number Diff line number Diff 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" )
You can’t perform that action at this time.
0 commit comments