-
Notifications
You must be signed in to change notification settings - Fork 28.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-11624][SPARK-11972][SQL]fix commands that need hive to exec #9589
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,14 +24,14 @@ import scala.collection.JavaConverters._ | |
import scala.language.reflectiveCalls | ||
|
||
import org.apache.hadoop.fs.Path | ||
import org.apache.hadoop.hive.cli.CliSessionState | ||
import org.apache.hadoop.hive.conf.HiveConf | ||
import org.apache.hadoop.hive.metastore.{TableType => HTableType} | ||
import org.apache.hadoop.hive.metastore.api.{Database, FieldSchema} | ||
import org.apache.hadoop.hive.ql.{metadata, Driver} | ||
import org.apache.hadoop.hive.ql.metadata.Hive | ||
import org.apache.hadoop.hive.ql.processors._ | ||
import org.apache.hadoop.hive.ql.session.SessionState | ||
import org.apache.hadoop.hive.shims.{HadoopShims, ShimLoader} | ||
import org.apache.hadoop.security.UserGroupInformation | ||
|
||
import org.apache.spark.{Logging, SparkConf, SparkException} | ||
|
@@ -104,29 +104,39 @@ private[hive] class HiveClientImpl( | |
} | ||
|
||
val ret = try { | ||
val initialConf = new HiveConf(classOf[SessionState]) | ||
// HiveConf is a Hadoop Configuration, which has a field of classLoader and | ||
// the initial value will be the current thread's context class loader | ||
// (i.e. initClassLoader at here). | ||
// We call initialConf.setClassLoader(initClassLoader) at here to make | ||
// this action explicit. | ||
initialConf.setClassLoader(initClassLoader) | ||
config.foreach { case (k, v) => | ||
if (k.toLowerCase.contains("password")) { | ||
logDebug(s"Hive Config: $k=xxx") | ||
} else { | ||
logDebug(s"Hive Config: $k=$v") | ||
// originState will be created if not exists, will never be null | ||
val originalState = SessionState.get() | ||
if (originalState.isInstanceOf[CliSessionState]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if you don't special case this? Why is this dependent on the type of the session state and not just on the fact that a session has already been started? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the |
||
// In `SparkSQLCLIDriver`, we have already started a `CliSessionState`, | ||
// which contains information like configurations from command line. Later | ||
// we call `SparkSQLEnv.init()` there, which would run into this part again. | ||
// so we should keep `conf` and reuse the existing instance of `CliSessionState`. | ||
originalState | ||
} else { | ||
val initialConf = new HiveConf(classOf[SessionState]) | ||
// HiveConf is a Hadoop Configuration, which has a field of classLoader and | ||
// the initial value will be the current thread's context class loader | ||
// (i.e. initClassLoader at here). | ||
// We call initialConf.setClassLoader(initClassLoader) at here to make | ||
// this action explicit. | ||
initialConf.setClassLoader(initClassLoader) | ||
config.foreach { case (k, v) => | ||
if (k.toLowerCase.contains("password")) { | ||
logDebug(s"Hive Config: $k=xxx") | ||
} else { | ||
logDebug(s"Hive Config: $k=$v") | ||
} | ||
initialConf.set(k, v) | ||
} | ||
initialConf.set(k, v) | ||
} | ||
val state = new SessionState(initialConf) | ||
if (clientLoader.cachedHive != null) { | ||
Hive.set(clientLoader.cachedHive.asInstanceOf[Hive]) | ||
val state = new SessionState(initialConf) | ||
if (clientLoader.cachedHive != null) { | ||
Hive.set(clientLoader.cachedHive.asInstanceOf[Hive]) | ||
} | ||
SessionState.start(state) | ||
state.out = new PrintStream(outputBuffer, true, "UTF-8") | ||
state.err = new PrintStream(outputBuffer, true, "UTF-8") | ||
state | ||
} | ||
SessionState.start(state) | ||
state.out = new PrintStream(outputBuffer, true, "UTF-8") | ||
state.err = new PrintStream(outputBuffer, true, "UTF-8") | ||
state | ||
} finally { | ||
Thread.currentThread().setContextClassLoader(original) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to change this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, Hive does the same thing.