aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcelo Vanzin <vanzin@cloudera.com>2017-03-03 18:44:31 -0800
committerXiao Li <gatorsmile@gmail.com>2017-03-03 18:44:31 -0800
commit9e5b4ce727cf262a14a411efded85ee1e50a88ed (patch)
treebf003d87b595c5256c9e1a9f0321a1973ae1520a
parenta6a7a95e2f3482d84fcd744713e43f80ea90e33a (diff)
downloadspark-9e5b4ce727cf262a14a411efded85ee1e50a88ed.tar.gz
spark-9e5b4ce727cf262a14a411efded85ee1e50a88ed.tar.bz2
spark-9e5b4ce727cf262a14a411efded85ee1e50a88ed.zip
[SPARK-19084][SQL] Ensure context class loader is set when initializing Hive.
A change in Hive 2.2 (most probably HIVE-13149) causes this code path to fail, since the call to "state.getConf.setClassLoader" does not actually change the context's class loader. Spark doesn't yet officially support Hive 2.2, but some distribution-specific metastore client libraries may have that change (as certain versions of CDH already do), and this also makes it easier to support 2.2 when it comes out. Tested with existing unit tests; we've also used this patch extensively with Hive metastore client jars containing the offending patch. Author: Marcelo Vanzin <vanzin@cloudera.com> Closes #17154 from vanzin/SPARK-19804.
-rw-r--r--sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala11
1 files changed, 8 insertions, 3 deletions
diff --git a/sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala b/sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala
index 8f98c8f447..7acaa9a7ab 100644
--- a/sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala
+++ b/sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala
@@ -269,16 +269,21 @@ private[hive] class HiveClientImpl(
*/
def withHiveState[A](f: => A): A = retryLocked {
val original = Thread.currentThread().getContextClassLoader
- // Set the thread local metastore client to the client associated with this HiveClientImpl.
- Hive.set(client)
+ val originalConfLoader = state.getConf.getClassLoader
// The classloader in clientLoader could be changed after addJar, always use the latest
- // classloader
+ // classloader. We explicitly set the context class loader since "conf.setClassLoader" does
+ // not do that, and the Hive client libraries may need to load classes defined by the client's
+ // class loader.
+ Thread.currentThread().setContextClassLoader(clientLoader.classLoader)
state.getConf.setClassLoader(clientLoader.classLoader)
+ // Set the thread local metastore client to the client associated with this HiveClientImpl.
+ Hive.set(client)
// setCurrentSessionState will use the classLoader associated
// with the HiveConf in `state` to override the context class loader of the current
// thread.
shim.setCurrentSessionState(state)
val ret = try f finally {
+ state.getConf.setClassLoader(originalConfLoader)
Thread.currentThread().setContextClassLoader(original)
HiveCatalogMetrics.incrementHiveClientCalls(1)
}