1717
1818package org .apache .spark .sql .hive
1919
20- import java .io .{BufferedReader , InputStreamReader , PrintStream }
20+ import java .io .{BufferedReader , File , InputStreamReader , PrintStream }
2121import java .sql .Timestamp
2222import java .util .{ArrayList => JArrayList }
2323
@@ -36,8 +36,9 @@ import org.apache.hadoop.hive.ql.processors._
3636import org .apache .hadoop .hive .ql .session .SessionState
3737import org .apache .hadoop .hive .serde2 .io .{DateWritable , TimestampWritable }
3838
39- import org .apache .spark .SparkContext
39+ import org .apache .spark .{ SparkConf , SparkContext }
4040import org .apache .spark .annotation .Experimental
41+ import org .apache .spark .deploy .SparkHadoopUtil
4142import org .apache .spark .sql ._
4243import org .apache .spark .sql .catalyst .analysis .{Analyzer , EliminateSubQueries , OverrideCatalog , OverrideFunctionRegistry }
4344import org .apache .spark .sql .catalyst .plans .logical ._
@@ -105,12 +106,12 @@ class HiveContext(sc: SparkContext) extends SQLContext(sc) {
105106 * Spark SQL for execution.
106107 */
107108 protected [hive] def hiveMetastoreVersion : String =
108- getConf(HIVE_METASTORE_VERSION , " 0.13.1 " )
109+ getConf(HIVE_METASTORE_VERSION , hiveExecutionVersion )
109110
110111 /**
111112 * The location of the jars that should be used to instantiate the HiveMetastoreClient. This
112113 * property can be one of three options:
113- * - a colon-separated list of jar files or directories for hive and hadoop.
114+ * - a classpath in the standard format for both hive and hadoop.
114115 * - builtin - attempt to discover the jars that were used to load Spark SQL and use those. This
115116 * option is only valid when using the execution version of Hive.
116117 * - maven - download the correct version of hive on demand from maven.
@@ -121,22 +122,6 @@ class HiveContext(sc: SparkContext) extends SQLContext(sc) {
121122 @ transient
122123 protected [sql] lazy val substitutor = new VariableSubstitution ()
123124
124-
125- /** A local instance of hive that is only used for execution. */
126- protected [hive] lazy val localMetastore = {
127- val temp = Utils .createTempDir()
128- temp.delete()
129- temp
130- }
131-
132- @ transient
133- protected [hive] lazy val executionConf = new HiveConf ()
134- executionConf.set(
135- " javax.jdo.option.ConnectionURL" , s " jdbc:derby:;databaseName= $localMetastore;create=true " )
136-
137- /** The version of hive used internally by Spark SQL. */
138- lazy val hiveExecutionVersion : String = " 0.13.1"
139-
140125 /**
141126 * The copy of the hive client that is used for execution. Currently this must always be
142127 * Hive 13 as this is the version of Hive that is packaged with Spark SQL. This copy of the
@@ -149,9 +134,7 @@ class HiveContext(sc: SparkContext) extends SQLContext(sc) {
149134 logInfo(s " Initilizing execution hive, version $hiveExecutionVersion" )
150135 new ClientWrapper (
151136 version = IsolatedClientLoader .hiveVersion(hiveExecutionVersion),
152- config = Map (
153- " javax.jdo.option.ConnectionURL" ->
154- s " jdbc:derby:;databaseName= $localMetastore;create=true " ))
137+ config = newTemporaryConfiguation())
155138 }
156139 SessionState .setCurrentSessionState(executionHive.state)
157140
@@ -203,11 +186,13 @@ class HiveContext(sc: SparkContext) extends SQLContext(sc) {
203186 // Convert to files and expand any directories.
204187 val jars =
205188 hiveMetastoreJars
206- .split(" :" )
207- .map(new java.io.File (_))
189+ .split(File .pathSeparator)
208190 .flatMap {
209- case f if f.isDirectory => f.listFiles()
210- case f => f :: Nil
191+ case path if path.endsWith(" *" ) =>
192+ val directory = new File (path.dropRight(1 ))
193+ directory.listFiles.filter(_.getName.endsWith(" jar" ))
194+ case path =>
195+ new File (path) :: Nil
211196 }
212197 .map(_.toURI.toURL)
213198
@@ -471,9 +456,20 @@ class HiveContext(sc: SparkContext) extends SQLContext(sc) {
471456
472457
473458private [hive] object HiveContext {
459+ /** The version of hive used internally by Spark SQL. */
460+ val hiveExecutionVersion : String = " 0.13.1"
461+
474462 val HIVE_METASTORE_VERSION : String = " spark.sql.hive.metastore.version"
475463 val HIVE_METASTORE_JARS : String = " spark.sql.hive.metastore.jars"
476464
465+ /** Constructs a configuration for hive, where the metastore is located in a temp directory. */
466+ def newTemporaryConfiguation (): Map [String , String ] = {
467+ val tempDir = Utils .createTempDir()
468+ val localMetastore = new File (tempDir, " metastore" )
469+ Map (
470+ " javax.jdo.option.ConnectionURL" -> s " jdbc:derby:;databaseName= $localMetastore;create=true " )
471+ }
472+
477473 protected val primitiveTypes =
478474 Seq (StringType , IntegerType , LongType , DoubleType , FloatType , BooleanType , ByteType ,
479475 ShortType , DateType , TimestampType , BinaryType )
0 commit comments