[SPARK-10121] [SQL] Thrift server always use the latest class loader 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.
This commit is contained in:
parent
642c43c81c
commit
a0c0aae1de
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue