Repository: hive
Updated Branches:
  refs/heads/master 74c7c2cd9 -> 4f3e2c614


HIVE-15166: Provide beeline option to set the jline history max size (Eric Lin, 
reviewed by Aihua Xu)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/4f3e2c61
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/4f3e2c61
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/4f3e2c61

Branch: refs/heads/master
Commit: 4f3e2c6145468bafa47834723a766defde3b96b6
Parents: 74c7c2c
Author: Aihua Xu <[email protected]>
Authored: Thu Mar 16 11:25:43 2017 -0400
Committer: Aihua Xu <[email protected]>
Committed: Thu Mar 16 11:25:43 2017 -0400

----------------------------------------------------------------------
 beeline/src/java/org/apache/hive/beeline/BeeLine.java  |  1 +
 .../src/java/org/apache/hive/beeline/BeeLineOpts.java  | 13 +++++++++++++
 beeline/src/main/resources/BeeLine.properties          |  1 +
 .../org/apache/hive/beeline/TestBeelineArgParsing.java | 12 ++++++++++++
 4 files changed, 27 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/4f3e2c61/beeline/src/java/org/apache/hive/beeline/BeeLine.java
----------------------------------------------------------------------
diff --git a/beeline/src/java/org/apache/hive/beeline/BeeLine.java 
b/beeline/src/java/org/apache/hive/beeline/BeeLine.java
index 3c8fccc..11526a7 100644
--- a/beeline/src/java/org/apache/hive/beeline/BeeLine.java
+++ b/beeline/src/java/org/apache/hive/beeline/BeeLine.java
@@ -538,6 +538,7 @@ public class BeeLine implements Closeable {
       public void run() {
         try {
           if (history != null) {
+            history.setMaxSize(getOpts().getMaxHistoryRows());
             history.flush();
           }
         } catch (IOException e) {

http://git-wip-us.apache.org/repos/asf/hive/blob/4f3e2c61/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java
----------------------------------------------------------------------
diff --git a/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java 
b/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java
index 7e6846d..048d744 100644
--- a/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java
+++ b/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java
@@ -45,6 +45,7 @@ import jline.Terminal;
 import jline.TerminalFactory;
 import jline.console.completer.Completer;
 import jline.console.completer.StringsCompleter;
+import jline.console.history.MemoryHistory;
 import org.apache.hadoop.hive.conf.HiveConf;
 
 class BeeLineOpts implements Completer {
@@ -100,6 +101,7 @@ class BeeLineOpts implements Completer {
 
   private final File rcFile = new File(saveDir(), "beeline.properties");
   private String historyFile = new File(saveDir(), 
"history").getAbsolutePath();
+  private int maxHistoryRows = MemoryHistory.DEFAULT_MAX_SIZE;
 
   private String scriptFile = null;
   private String[] initFiles = null;
@@ -431,6 +433,17 @@ class BeeLineOpts implements Completer {
     return historyFile;
   }
 
+  /**
+   * @param numRows - the number of rows to store in history file
+   */
+  public void setMaxHistoryRows(int numRows) {
+    this.maxHistoryRows = numRows;
+  }
+
+  public int getMaxHistoryRows() {
+    return maxHistoryRows;
+  }
+
   public void setScriptFile(String scriptFile) {
     this.scriptFile = scriptFile;
   }

http://git-wip-us.apache.org/repos/asf/hive/blob/4f3e2c61/beeline/src/main/resources/BeeLine.properties
----------------------------------------------------------------------
diff --git a/beeline/src/main/resources/BeeLine.properties 
b/beeline/src/main/resources/BeeLine.properties
index e33b812..7011221 100644
--- a/beeline/src/main/resources/BeeLine.properties
+++ b/beeline/src/main/resources/BeeLine.properties
@@ -202,6 +202,7 @@ cmd-usage: Usage: java org.apache.hive.cli.beeline.BeeLine 
\n \
 \  --delimiterForDSV=DELIMITER     specify the delimiter for 
delimiter-separated values output format (default: |)\n \
 \  --isolation=LEVEL               set the transaction isolation level\n \
 \  --nullemptystring=[true/false]  set to true to get historic behavior of 
printing null as empty string\n \
+\  --maxHistoryRows=MAXHISTORYROWS The maximum number of rows to store beeline 
history.\n \
 \  --help                          display this message\n \
 \n \
 \  Example:\n \

http://git-wip-us.apache.org/repos/asf/hive/blob/4f3e2c61/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java
----------------------------------------------------------------------
diff --git 
a/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java 
b/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java
index d73d374..2884cc8 100644
--- a/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java
+++ b/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java
@@ -319,4 +319,16 @@ public class TestBeelineArgParsing {
     Assert.assertTrue(bl.properties.get(0).equals("props"));
     bl.close();
   }
+
+  /**
+   * Test maxHistoryRows parameter option.
+   */
+  @Test
+  public void testMaxHistoryRows() throws Exception {
+    TestBeeline bl = new TestBeeline();
+    String args[] = new String[] {"--maxHistoryRows=100"};
+    Assert.assertEquals(0, bl.initArgs(args));
+    Assert.assertTrue(bl.getOpts().getMaxHistoryRows() == 100);
+    bl.close();
+  }
 }

Reply via email to