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 BeeLine(boolean isBeeLine) { public void run() { try { if (history != null) { + history.setMaxSize(getOpts().getMaxHistoryRows()); history.flush(); } } catch (IOException e) { diff --git a/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java b/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java index 9f330e3..4e0ac0e 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.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 { @@ -101,6 +102,7 @@ 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; @@ -432,6 +434,17 @@ public String getHistoryFile() { 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; } diff --git a/beeline/src/main/resources/BeeLine.properties b/beeline/src/main/resources/BeeLine.properties index af86284..c810078 100644 --- a/beeline/src/main/resources/BeeLine.properties +++ b/beeline/src/main/resources/BeeLine.properties @@ -204,6 +204,7 @@ cmd-usage: Usage: java org.apache.hive.cli.beeline.BeeLine \n \ \ --nullemptystring=[true/false] set to true to get historic behavior of printing null as empty string\n \ \ --showConnectedUrl=[true/false] Prompt HiveServer2's URI to which this beeline connected.\n \ \ Only works for HiveServer2 cluster mode.\n \ +\ --maxHistoryRows=MAXHISTORYROWS The maximum number of rows to store beeline history.\n \ \ --help display this message\n \ \n \ \ Example:\n \ 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 void testPropertyFile() throws Exception { 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(); + } }