Skip to content

Commit

Permalink
[SPARK-10121] [SQL] Thrift server always use the latest class loader …
Browse files Browse the repository at this point in the history
…provided by the conf of executionHive's state

https://issues.apache.org/jira/browse/SPARK-10121

Looks like the problem is that if we add a jar through another thread, the thread handling the JDBC session will not get the latest classloader.

Author: Yin Huai <yhuai@databricks.com>

Closes #8368 from yhuai/SPARK-10121.
  • Loading branch information
yhuai authored and liancheng committed Aug 25, 2015
1 parent 642c43c commit a0c0aae
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ private[hive] class SparkExecuteStatementOperation(

// User information is part of the metastore client member in Hive
hiveContext.setSession(currentSqlSession)
// Always use the latest class loader provided by executionHive's state.
val executionHiveClassLoader =
hiveContext.executionHive.state.getConf.getClassLoader
sessionHive.getConf.setClassLoader(executionHiveClassLoader)
parentSessionState.getConf.setClassLoader(executionHiveClassLoader)

Hive.set(sessionHive)
SessionState.setCurrentSessionState(parentSessionState)
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,60 @@ class HiveThriftBinaryServerSuite extends HiveThriftJdbcTest {
rs2.close()
}
}

test("test add jar") {
withMultipleConnectionJdbcStatement(
{
statement =>
val jarFile =
"../hive/src/test/resources/hive-hcatalog-core-0.13.1.jar"
.split("/")
.mkString(File.separator)

statement.executeQuery(s"ADD JAR $jarFile")
},

{
statement =>
val queries = Seq(
"DROP TABLE IF EXISTS smallKV",
"CREATE TABLE smallKV(key INT, val STRING)",
s"LOAD DATA LOCAL INPATH '${TestData.smallKv}' OVERWRITE INTO TABLE smallKV",
"DROP TABLE IF EXISTS addJar",
"""CREATE TABLE addJar(key string)
|ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
""".stripMargin)

queries.foreach(statement.execute)

statement.executeQuery(
"""
|INSERT INTO TABLE addJar SELECT 'k1' as key FROM smallKV limit 1
""".stripMargin)

val actualResult =
statement.executeQuery("SELECT key FROM addJar")
val actualResultBuffer = new collection.mutable.ArrayBuffer[String]()
while (actualResult.next()) {
actualResultBuffer += actualResult.getString(1)
}
actualResult.close()

val expectedResult =
statement.executeQuery("SELECT 'k1'")
val expectedResultBuffer = new collection.mutable.ArrayBuffer[String]()
while (expectedResult.next()) {
expectedResultBuffer += expectedResult.getString(1)
}
expectedResult.close()

assert(expectedResultBuffer === actualResultBuffer)

statement.executeQuery("DROP TABLE IF EXISTS addJar")
statement.executeQuery("DROP TABLE IF EXISTS smallKV")
}
)
}
}

class HiveThriftHttpServerSuite extends HiveThriftJdbcTest {
Expand Down

0 comments on commit a0c0aae

Please sign in to comment.