aboutsummaryrefslogtreecommitdiff
path: root/sql/hive-thriftserver/src
diff options
context:
space:
mode:
authorDaoyuan Wang <daoyuan.wang@intel.com>2015-11-24 23:32:05 +0800
committerCheng Lian <lian@databricks.com>2015-11-24 23:32:05 +0800
commit5889880fbe9628681042036892ef7ebd4f0857b4 (patch)
tree01e704aba16a5ff1422a815e86138aec88a60a1a /sql/hive-thriftserver/src
parentd4a5e6f719079639ffd38470f4d8d1f6fde3228d (diff)
downloadspark-5889880fbe9628681042036892ef7ebd4f0857b4.tar.gz
spark-5889880fbe9628681042036892ef7ebd4f0857b4.tar.bz2
spark-5889880fbe9628681042036892ef7ebd4f0857b4.zip
[SPARK-11592][SQL] flush spark-sql command line history to history file
Currently, `spark-sql` would not flush command history when exiting. Author: Daoyuan Wang <daoyuan.wang@intel.com> Closes #9563 from adrian-wang/jline.
Diffstat (limited to 'sql/hive-thriftserver/src')
-rw-r--r--sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLCLIDriver.scala16
1 files changed, 16 insertions, 0 deletions
diff --git a/sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLCLIDriver.scala b/sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLCLIDriver.scala
index 6419002a2a..4b928e600b 100644
--- a/sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLCLIDriver.scala
+++ b/sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLCLIDriver.scala
@@ -194,6 +194,22 @@ private[hive] object SparkSQLCLIDriver extends Logging {
logWarning(e.getMessage)
}
+ // add shutdown hook to flush the history to history file
+ Runtime.getRuntime.addShutdownHook(new Thread(new Runnable() {
+ override def run() = {
+ reader.getHistory match {
+ case h: FileHistory =>
+ try {
+ h.flush()
+ } catch {
+ case e: IOException =>
+ logWarning("WARNING: Failed to write command history file: " + e.getMessage)
+ }
+ case _ =>
+ }
+ }
+ }))
+
// TODO: missing
/*
val clientTransportTSocketField = classOf[CliSessionState].getDeclaredField("transport")