@@ -122,6 +122,27 @@ class HiveContext(sc: SparkContext) extends SQLContext(sc) {
122122 protected [hive] def hiveMetastoreJars : String =
123123 getConf(HIVE_METASTORE_JARS , " builtin" )
124124
125+ /**
126+ * A comma separated list of class prefixes that should be loaded using the classloader that
127+ * is shared between Spark SQL and a specific version of Hive. An example of classes that should
128+ * be shared is JDBC drivers that are needed to talk to the metastore. Other classes that need
129+ * to be shared are those that interact with classes that are already shared. For example,
130+ * custom appenders that are used by log4j.
131+ */
132+ protected [hive] def hiveMetastoreSharedPrefixes : Seq [String ] =
133+ getConf(" spark.sql.hive.metastore.sharedPrefixes" , jdbcPrefixes).split(" ," )
134+
135+ private def jdbcPrefixes = Seq (
136+ " com.mysql.jdbc" , " org.postgresql" , " com.microsoft.sqlserver" , " oracle.jdbc" ).mkString(" ," )
137+
138+ /**
139+ * A comma separated list of class prefixes that should explicitly be reloaded for each version
140+ * of Hive that Spark SQL is communicating with. For example, Hive UDFs that are declared in a
141+ * prefix that typically would be shared (i.e. org.apache.spark.*)
142+ */
143+ protected [hive] def hiveMetastoreBarrierPrefixes : Seq [String ] =
144+ getConf(" spark.sql.hive.metastore.barrierPrefixes" , " " ).split(" ," )
145+
125146 @ transient
126147 protected [sql] lazy val substitutor = new VariableSubstitution ()
127148
@@ -179,12 +200,14 @@ class HiveContext(sc: SparkContext) extends SQLContext(sc) {
179200 version = metaVersion,
180201 execJars = jars.toSeq,
181202 config = allConfig,
182- isolationOn = true )
203+ isolationOn = true ,
204+ barrierPrefixes = hiveMetastoreBarrierPrefixes,
205+ sharedPrefixes = hiveMetastoreSharedPrefixes)
183206 } else if (hiveMetastoreJars == " maven" ) {
184207 // TODO: Support for loading the jars from an already downloaded location.
185208 logInfo(
186209 s " Initializing HiveMetastoreConnection version $hiveMetastoreVersion using maven. " )
187- IsolatedClientLoader .forVersion(hiveMetastoreVersion, allConfig )
210+ IsolatedClientLoader .forVersion(hiveMetastoreVersion, allConfig)
188211 } else {
189212 // Convert to files and expand any directories.
190213 val jars =
@@ -210,7 +233,9 @@ class HiveContext(sc: SparkContext) extends SQLContext(sc) {
210233 version = metaVersion,
211234 execJars = jars.toSeq,
212235 config = allConfig,
213- isolationOn = true )
236+ isolationOn = true ,
237+ barrierPrefixes = hiveMetastoreBarrierPrefixes,
238+ sharedPrefixes = hiveMetastoreSharedPrefixes)
214239 }
215240 isolatedLoader.client
216241 }
0 commit comments