Skip to content

Commit 81bb366

Browse files
committed
comments from vanzin
1 parent 5f3945e commit 81bb366

File tree

4 files changed

+37
-44
lines changed

4 files changed

+37
-44
lines changed

sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLCLIDriver.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ private[hive] object SparkSQLCLIDriver {
8181
}
8282
val cliConf = new HiveConf(classOf[SessionState])
8383
// Override the location of the metastore since this is only used for local execution.
84-
cliConf.set(
85-
"javax.jdo.option.ConnectionURL", s"jdbc:derby:;databaseName=$localMetastore;create=true")
84+
HiveContext.newTemporaryConfiguation().foreach {
85+
case (key, value) => cliConf.set(key, value)
86+
}
8687
val sessionState = new CliSessionState(cliConf)
8788

8889
sessionState.in = System.in
@@ -103,7 +104,7 @@ private[hive] object SparkSQLCLIDriver {
103104
sessionState.cmdProperties.entrySet().foreach { item =>
104105
val key = item.getKey.asInstanceOf[String]
105106
val value = item.getValue.asInstanceOf[String]
106-
// We do not propogate metastore options to the execution copy of hive.
107+
// We do not propagate metastore options to the execution copy of hive.
107108
if (key != "javax.jdo.option.ConnectionURL") {
108109
conf.set(key, value)
109110
sessionState.getOverriddenConfigurations.put(key, value)

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

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package org.apache.spark.sql.hive
1919

20-
import java.io.{BufferedReader, InputStreamReader, PrintStream}
20+
import java.io.{BufferedReader, File, InputStreamReader, PrintStream}
2121
import java.sql.Timestamp
2222
import java.util.{ArrayList => JArrayList}
2323

@@ -36,8 +36,9 @@ import org.apache.hadoop.hive.ql.processors._
3636
import org.apache.hadoop.hive.ql.session.SessionState
3737
import org.apache.hadoop.hive.serde2.io.{DateWritable, TimestampWritable}
3838

39-
import org.apache.spark.SparkContext
39+
import org.apache.spark.{SparkConf, SparkContext}
4040
import org.apache.spark.annotation.Experimental
41+
import org.apache.spark.deploy.SparkHadoopUtil
4142
import org.apache.spark.sql._
4243
import org.apache.spark.sql.catalyst.analysis.{Analyzer, EliminateSubQueries, OverrideCatalog, OverrideFunctionRegistry}
4344
import 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

473458
private[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)

sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/CreateTableAsSelect.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ case class CreateTableAsSelect(
6060
schema =
6161
query.output.map(c =>
6262
HiveColumn(c.name, HiveMetastoreTypes.toMetastoreType(c.dataType), null)),
63-
inputFormat =
64-
tableDesc.inputFormat.orElse(Some(classOf[TextInputFormat].getName)),
65-
outputFormat =
66-
tableDesc.outputFormat
67-
.orElse(Some(classOf[HiveIgnoreKeyTextOutputFormat[Text, Text]].getName)),
68-
serde = tableDesc.serde.orElse(Some(classOf[LazySimpleSerDe].getName())))
63+
inputFormat =
64+
tableDesc.inputFormat.orElse(Some(classOf[TextInputFormat].getName)),
65+
outputFormat =
66+
tableDesc.outputFormat
67+
.orElse(Some(classOf[HiveIgnoreKeyTextOutputFormat[Text, Text]].getName)),
68+
serde = tableDesc.serde.orElse(Some(classOf[LazySimpleSerDe].getName())))
6969
hiveContext.catalog.client.createTable(withSchema)
7070

7171
// Get the Metastore Relation

sql/hive/src/main/scala/org/apache/spark/sql/hive/test/TestHive.scala

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ object TestHive
6363
class TestHiveContext(sc: SparkContext) extends HiveContext(sc) {
6464
self =>
6565

66+
import HiveContext._
67+
6668
// By clearing the port we force Spark to pick a new one. This allows us to rerun tests
6769
// without restarting the JVM.
6870
System.clearProperty("spark.hostPort")
@@ -71,16 +73,10 @@ class TestHiveContext(sc: SparkContext) extends HiveContext(sc) {
7173
hiveconf.set("hive.plan.serialization.format", "javaXML")
7274

7375
lazy val warehousePath = Utils.createTempDir()
74-
lazy val metastorePath = {
75-
val temp = Utils.createTempDir()
76-
temp.delete()
77-
temp
78-
}
7976

8077
/** Sets up the system initially or after a RESET command */
81-
protected override def configure(): Map[String, String] = Map(
82-
"javax.jdo.option.ConnectionURL" -> s"jdbc:derby:;databaseName=$metastorePath;create=true",
83-
"hive.metastore.warehouse.dir" -> warehousePath.toString)
78+
protected override def configure(): Map[String, String] =
79+
newTemporaryConfiguation() ++ Map("hive.metastore.warehouse.dir" -> warehousePath.toString)
8480

8581
val testTempDir = Utils.createTempDir()
8682

0 commit comments

Comments
 (0)