Author: gopalv
Date: Tue Jan 13 14:57:47 2015
New Revision: 1651367

URL: http://svn.apache.org/r1651367
Log:
HIVE-9310 : Flush hive CLI history to disk on exit (Gopal V, reviewed by 
Prasanth J)

Modified:
    hive/trunk/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java

Modified: hive/trunk/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java
URL: 
http://svn.apache.org/viewvc/hive/trunk/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java?rev=1651367&r1=1651366&r2=1651367&view=diff
==============================================================================
--- hive/trunk/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java (original)
+++ hive/trunk/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java Tue Jan 
13 14:57:47 2015
@@ -40,6 +40,7 @@ import com.google.common.base.Splitter;
 import jline.console.ConsoleReader;
 import jline.console.completer.Completer;
 import jline.console.history.FileHistory;
+import jline.console.history.PersistentHistory;
 import jline.console.completer.StringsCompleter;
 import jline.console.completer.ArgumentCompleter;
 import jline.console.completer.ArgumentCompleter.ArgumentDelimiter;
@@ -721,10 +722,12 @@ public class CliDriver {
     String line;
     final String HISTORYFILE = ".hivehistory";
     String historyDirectory = System.getProperty("user.home");
+    PersistentHistory history = null;
     try {
       if ((new File(historyDirectory)).exists()) {
         String historyFile = historyDirectory + File.separator + HISTORYFILE;
-        reader.setHistory(new FileHistory(new File(historyFile)));
+        history = new FileHistory(new File(historyFile));
+        reader.setHistory(history);
       } else {
         System.err.println("WARNING: Directory for Hive history file: " + 
historyDirectory +
                            " does not exist.   History will not be available 
during this session.");
@@ -759,6 +762,10 @@ public class CliDriver {
         continue;
       }
     }
+
+    if (history != null) {
+      history.flush();
+    }
     return ret;
   }
 


Reply via email to