diff --git a/.gitignore b/.gitignore index 47c59da..e6d8eb8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ build +out build-eclipse .arc_jira_lib .classpath* diff --git a/beeline/src/java/org/apache/hive/beeline/BeeLine.java b/beeline/src/java/org/apache/hive/beeline/BeeLine.java index e9111c4..7aef172 100644 --- a/beeline/src/java/org/apache/hive/beeline/BeeLine.java +++ b/beeline/src/java/org/apache/hive/beeline/BeeLine.java @@ -1247,6 +1247,7 @@ public void run() { History h = consoleReader.getHistory(); if (h instanceof FileHistory) { try { + ((FileHistory) h).setMaxSize(getOpts().getMaxHistoryRows()); ((FileHistory) h).flush(); } catch (IOException e) { error(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 141f0c6..3b383d3 100644 --- a/beeline/src/main/resources/BeeLine.properties +++ b/beeline/src/main/resources/BeeLine.properties @@ -203,6 +203,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(); + } }