Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[SPARK-11595][SQL][BRANCH-1.5] Fixes ADD JAR when the input path cont…
…ains URL scheme

This PR backports apache#9569 to branch-1.5.

Author: Cheng Lian <[email protected]>

Closes apache#9570 from liancheng/spark-11595.for-branch-1.5.
  • Loading branch information
liancheng authored and yhuai committed Nov 12, 2015
commit b478ee3743dd542004f2715e6d00eb999d1a06dd
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

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

import java.io.File

import org.apache.hadoop.fs.Path
import org.apache.hadoop.hive.metastore.MetaStoreUtils
import org.apache.spark.sql._
import org.apache.spark.sql.catalyst.{TableIdentifier, SqlParser}
Expand Down Expand Up @@ -90,7 +93,17 @@ case class AddJar(path: String) extends RunnableCommand {
val currentClassLoader = Utils.getContextOrSparkClassLoader

// Add jar to current context
val jarURL = new java.io.File(path).toURI.toURL
val jarURL = {
val uri = new Path(path).toUri
if (uri.getScheme == null) {
// `path` is a local file path without a URL scheme
new File(path).toURI.toURL
} else {
// `path` is a URL with a scheme
uri.toURL
}
}

val newClassLoader = new java.net.URLClassLoader(Array(jarURL), currentClassLoader)
Thread.currentThread.setContextClassLoader(newClassLoader)
// We need to explicitly set the class loader associated with the conf in executionHive's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils {
private val sqlContext = _sqlContext

test("UDTF") {
sql(s"ADD JAR ${TestHive.getHiveFile("TestUDTF.jar").getCanonicalPath()}")
val jarPath = TestHive.getHiveFile("TestUDTF.jar").getCanonicalPath

// SPARK-11595 Fixes ADD JAR when input path contains URL scheme
val jarURL = s"file://$jarPath"

sql(s"ADD JAR $jarURL")
// The function source code can be found at:
// https://cwiki.apache.org/confluence/display/Hive/DeveloperGuide+UDTF
sql(
Expand Down