Skip to content

Commit 693939c

Browse files
author
Marcelo Vanzin
committed
[SPARK-16349][sql] Fall back to isolated class loader when classes not found.
Some Hadoop classes needed by the Hive metastore client jars are not present in Spark's packaging (for example, "org/apache/hadoop/mapred/MRVersion"). So if the parent class loader fails to find a class, try to load it from the isolated class loader, in case it's available there. I also took the opportunity to remove the HIVE_EXECUTION_VERSION constant since it's not used anywhere. Tested by setting spark.sql.hive.metastore.jars to local paths with Hive/Hadoop libraries and verifying that Spark can talk to the metastore.
1 parent d59ba8e commit 693939c

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveUtils.scala

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ private[spark] object HiveUtils extends Logging {
6161
.stringConf
6262
.createWithDefault(hiveExecutionVersion)
6363

64-
val HIVE_EXECUTION_VERSION = SQLConfigBuilder("spark.sql.hive.version")
65-
.doc("Version of Hive used internally by Spark SQL.")
66-
.stringConf
67-
.createWithDefault(hiveExecutionVersion)
68-
6964
val HIVE_METASTORE_JARS = SQLConfigBuilder("spark.sql.hive.metastore.jars")
7065
.doc(s"""
7166
| Location of the jars that should be used to instantiate the HiveMetastoreClient.

sql/hive/src/main/scala/org/apache/spark/sql/hive/client/IsolatedClientLoader.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,15 @@ private[hive] class IsolatedClientLoader(
220220
logDebug(s"hive class: $name - ${getResource(classToPath(name))}")
221221
super.loadClass(name, resolve)
222222
} else {
223-
// For shared classes, we delegate to baseClassLoader.
223+
// For shared classes, we delegate to baseClassLoader, but fall back in case the
224+
// class is not found.
224225
logDebug(s"shared class: $name")
225-
baseClassLoader.loadClass(name)
226+
try {
227+
baseClassLoader.loadClass(name)
228+
} catch {
229+
case _: ClassNotFoundException =>
230+
super.loadClass(name, resolve)
231+
}
226232
}
227233
}
228234
}
@@ -264,7 +270,7 @@ private[hive] class IsolatedClientLoader(
264270
throw new ClassNotFoundException(
265271
s"$cnf when creating Hive client using classpath: ${execJars.mkString(", ")}\n" +
266272
"Please make sure that jars for your version of hive and hadoop are included in the " +
267-
s"paths passed to ${HiveUtils.HIVE_METASTORE_JARS}.", e)
273+
s"paths passed to ${HiveUtils.HIVE_METASTORE_JARS.key}.", e)
268274
} else {
269275
throw e
270276
}

0 commit comments

Comments
 (0)