-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-26321][SQL] Improve the behavior of sql text splitting for the spark-sql command line #23276
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
Changes from all commits
9ab2865
92e5352
2fd9b7b
af6e885
91c6e13
fbdec3f
067b733
5ab280c
a7dc590
01c0cc5
c245ad4
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,7 +24,7 @@ import scala.collection.JavaConverters._ | |||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| import jline.console.ConsoleReader | ||||||||||||||||||||||||||||||||||||||||||||||
| import jline.console.history.FileHistory | ||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.commons.lang3.StringUtils | ||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.commons.lang.{StringUtils => ApacheStringUtils} | ||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.commons.logging.LogFactory | ||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.hadoop.conf.Configuration | ||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.hadoop.hive.cli.{CliDriver, CliSessionState, OptionsProcessor} | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -37,14 +37,16 @@ import org.apache.hadoop.hive.ql.session.SessionState | |||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.hadoop.security.{Credentials, UserGroupInformation} | ||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.log4j.Level | ||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.thrift.transport.TSocket | ||||||||||||||||||||||||||||||||||||||||||||||
| import sun.misc.{Signal, SignalHandler} | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.spark.SparkConf | ||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.spark.deploy.SparkHadoopUtil | ||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.spark.internal.Logging | ||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.spark.sql.AnalysisException | ||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.spark.sql.catalyst.util.StringUtils | ||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.spark.sql.hive.HiveUtils | ||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.spark.sql.hive.security.HiveDelegationTokenProvider | ||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.spark.util.ShutdownHookManager | ||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.spark.util.{ShutdownHookManager, Utils} | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||
| * This code doesn't support remote connections in Hive 1.2+, as the underlying CliDriver | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -143,8 +145,8 @@ private[hive] object SparkSQLCLIDriver extends Logging { | |||||||||||||||||||||||||||||||||||||||||||||
| // See also: code in ExecDriver.java | ||||||||||||||||||||||||||||||||||||||||||||||
| var loader = conf.getClassLoader | ||||||||||||||||||||||||||||||||||||||||||||||
| val auxJars = HiveConf.getVar(conf, HiveConf.ConfVars.HIVEAUXJARS) | ||||||||||||||||||||||||||||||||||||||||||||||
| if (StringUtils.isNotBlank(auxJars)) { | ||||||||||||||||||||||||||||||||||||||||||||||
| loader = Utilities.addToClassPath(loader, StringUtils.split(auxJars, ",")) | ||||||||||||||||||||||||||||||||||||||||||||||
| if (ApacheStringUtils.isNotBlank(auxJars)) { | ||||||||||||||||||||||||||||||||||||||||||||||
| loader = Utilities.addToClassPath(loader, ApacheStringUtils.split(auxJars, ",")) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| conf.setClassLoader(loader) | ||||||||||||||||||||||||||||||||||||||||||||||
| Thread.currentThread().setContextClassLoader(loader) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -309,12 +311,16 @@ private[hive] class SparkSQLCLIDriver extends CliDriver with Logging { | |||||||||||||||||||||||||||||||||||||||||||||
| private val conf: Configuration = | ||||||||||||||||||||||||||||||||||||||||||||||
| if (sessionState != null) sessionState.getConf else new Configuration() | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Force initializing SparkSQLEnv. This is put here but not object SparkSQLCliDriver | ||||||||||||||||||||||||||||||||||||||||||||||
| // because the Hive unit tests do not go through the main() code path. | ||||||||||||||||||||||||||||||||||||||||||||||
| if (!isRemoteMode) { | ||||||||||||||||||||||||||||||||||||||||||||||
| SparkSQLEnv.init() | ||||||||||||||||||||||||||||||||||||||||||||||
| if (sessionState.getIsSilent) { | ||||||||||||||||||||||||||||||||||||||||||||||
| SparkSQLEnv.sparkContext.setLogLevel(Level.WARN.toString) | ||||||||||||||||||||||||||||||||||||||||||||||
| // Utils.isTesing consists of env[SPARK_TESTING] or props[spark.testing] | ||||||||||||||||||||||||||||||||||||||||||||||
| // env is multi-process-level, props is single-process-level | ||||||||||||||||||||||||||||||||||||||||||||||
| // CliSuite with env[SPARK_TESTING] requires SparkSQLEnv | ||||||||||||||||||||||||||||||||||||||||||||||
| // props[spark.testing] acts as a switcher for SparkSQLCLIDriverSuite | ||||||||||||||||||||||||||||||||||||||||||||||
| if (!sys.props.contains("spark.testing")) { | ||||||||||||||||||||||||||||||||||||||||||||||
| SparkSQLEnv.init() | ||||||||||||||||||||||||||||||||||||||||||||||
| if (sessionState.getIsSilent) { | ||||||||||||||||||||||||||||||||||||||||||||||
| SparkSQLEnv.sparkContext.setLogLevel(Level.WARN.toString) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| // Hive 1.2 + not supported in CLI | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -331,6 +337,65 @@ private[hive] class SparkSQLCLIDriver extends CliDriver with Logging { | |||||||||||||||||||||||||||||||||||||||||||||
| console.printInfo(s"Spark master: $master, Application Id: $appId") | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // method body imported from Hive and translated from Java to Scala | ||||||||||||||||||||||||||||||||||||||||||||||
| override def processLine(line: String, allowInterrupting: Boolean): Int = { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
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. so the default
Contributor
Author
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. yes,there is a buggy impl in hive
Contributor
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. I checked the hive code and seems the Do you mean only Hive 1.2 has this bug? Maybe we should upgrade hive.
Contributor
Author
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. Yes,and I had not checked the impl on Hive master. We may judge which impl is better
Member
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. Upgrade the built-in Hive can fix this issue: |
||||||||||||||||||||||||||||||||||||||||||||||
| var oldSignal: SignalHandler = null | ||||||||||||||||||||||||||||||||||||||||||||||
| var interruptSignal: Signal = null | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (allowInterrupting) { | ||||||||||||||||||||||||||||||||||||||||||||||
| // Remember all threads that were running at the time we started line processing. | ||||||||||||||||||||||||||||||||||||||||||||||
| // Hook up the custom Ctrl+C handler while processing this line | ||||||||||||||||||||||||||||||||||||||||||||||
| interruptSignal = new Signal("INT") | ||||||||||||||||||||||||||||||||||||||||||||||
| oldSignal = Signal.handle(interruptSignal, new SignalHandler() { | ||||||||||||||||||||||||||||||||||||||||||||||
| private val cliThread = Thread.currentThread() | ||||||||||||||||||||||||||||||||||||||||||||||
|
Member
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's the meaning of cliThread, I don't find any usage. |
||||||||||||||||||||||||||||||||||||||||||||||
| private var interruptRequested: Boolean = false | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| override def handle(signal: Signal) { | ||||||||||||||||||||||||||||||||||||||||||||||
| val initialRequest = !interruptRequested | ||||||||||||||||||||||||||||||||||||||||||||||
| interruptRequested = true | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Kill the VM on second ctrl+c | ||||||||||||||||||||||||||||||||||||||||||||||
| if (!initialRequest) { | ||||||||||||||||||||||||||||||||||||||||||||||
| console.printInfo("Exiting the JVM") | ||||||||||||||||||||||||||||||||||||||||||||||
| System.exit(127) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Interrupt the CLI thread to stop the current statement and return | ||||||||||||||||||||||||||||||||||||||||||||||
| // to prompt | ||||||||||||||||||||||||||||||||||||||||||||||
| console.printInfo("Interrupting... Be patient, this might take some time.") | ||||||||||||||||||||||||||||||||||||||||||||||
| console.printInfo("Press Ctrl+C again to kill JVM") | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // First, kill any running Spark jobs | ||||||||||||||||||||||||||||||||||||||||||||||
| // TODO | ||||||||||||||||||||||||||||||||||||||||||||||
|
Member
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. I think Lines 60 to 81 in bc7592b
|
||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||
| var lastRet: Int = 0 | ||||||||||||||||||||||||||||||||||||||||||||||
| var ret: Int = 0 | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| for (command <- StringUtils.split(line)) { | ||||||||||||||||||||||||||||||||||||||||||||||
| ret = processCmd(command) | ||||||||||||||||||||||||||||||||||||||||||||||
| // wipe cli query state | ||||||||||||||||||||||||||||||||||||||||||||||
| sessionState.setCommandType(null) | ||||||||||||||||||||||||||||||||||||||||||||||
| lastRet = ret | ||||||||||||||||||||||||||||||||||||||||||||||
| val ignoreErrors = HiveConf.getBoolVar(conf, HiveConf.ConfVars.CLIIGNOREERRORS) | ||||||||||||||||||||||||||||||||||||||||||||||
| if (ret != 0 && !ignoreErrors) { | ||||||||||||||||||||||||||||||||||||||||||||||
| CommandProcessorFactory.clean(conf.asInstanceOf[HiveConf]) | ||||||||||||||||||||||||||||||||||||||||||||||
| return ret | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| CommandProcessorFactory.clean(conf.asInstanceOf[HiveConf]); | ||||||||||||||||||||||||||||||||||||||||||||||
| lastRet | ||||||||||||||||||||||||||||||||||||||||||||||
| } finally { | ||||||||||||||||||||||||||||||||||||||||||||||
| // Once we are done processing the line, restore the old handler | ||||||||||||||||||||||||||||||||||||||||||||||
| if (oldSignal != null && interruptSignal != null) { | ||||||||||||||||||||||||||||||||||||||||||||||
| Signal.handle(interruptSignal, oldSignal) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| override def processCmd(cmd: String): Int = { | ||||||||||||||||||||||||||||||||||||||||||||||
| val cmd_trimmed: String = cmd.trim() | ||||||||||||||||||||||||||||||||||||||||||||||
| val cmd_lower = cmd_trimmed.toLowerCase(Locale.ROOT) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||

Uh oh!
There was an error while loading. Please reload this page.