You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ha...@apache.org on 2016/01/31 22:09:09 UTC
hive git commit: HIVE-12780 : Fix the output of the history command
in Beeline (Shinichi Yamashita via Ashutosh Chauhan)
Repository: hive
Updated Branches:
refs/heads/master 8a44ade38 -> 47f847188
HIVE-12780 : Fix the output of the history command in Beeline (Shinichi Yamashita via Ashutosh Chauhan)
Signed-off-by: Ashutosh Chauhan <ha...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/47f84718
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/47f84718
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/47f84718
Branch: refs/heads/master
Commit: 47f847188d4371fc16badc7099c10658dc0a8828
Parents: 8a44ade
Author: Shinichi Yamashita <ya...@oss.nttdata.co.jp>
Authored: Thu Jan 7 06:25:00 2016 -0800
Committer: Ashutosh Chauhan <ha...@apache.org>
Committed: Sun Jan 31 13:08:53 2016 -0800
----------------------------------------------------------------------
.../java/org/apache/hive/beeline/Commands.java | 8 +++---
.../apache/hive/beeline/TestBeeLineHistory.java | 26 +++++++++++++++++++-
2 files changed, 30 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/47f84718/beeline/src/java/org/apache/hive/beeline/Commands.java
----------------------------------------------------------------------
diff --git a/beeline/src/java/org/apache/hive/beeline/Commands.java b/beeline/src/java/org/apache/hive/beeline/Commands.java
index 08f3846..22e2066 100644
--- a/beeline/src/java/org/apache/hive/beeline/Commands.java
+++ b/beeline/src/java/org/apache/hive/beeline/Commands.java
@@ -179,10 +179,12 @@ public class Commands {
public boolean history(String line) {
Iterator hist = beeLine.getConsoleReader().getHistory().entries();
- int index = 1;
+ String[] tmp;
while(hist.hasNext()){
- beeLine.output(beeLine.getColorBuffer().pad(index + ".", 6)
- .append(hist.next().toString()));
+ tmp = hist.next().toString().split(":", 2);
+ tmp[0] = Integer.toString(Integer.parseInt(tmp[0]) + 1);
+ beeLine.output(beeLine.getColorBuffer().pad(tmp[0], 6)
+ .append(":" + tmp[1]));
}
return true;
}
http://git-wip-us.apache.org/repos/asf/hive/blob/47f84718/beeline/src/test/org/apache/hive/beeline/TestBeeLineHistory.java
----------------------------------------------------------------------
diff --git a/beeline/src/test/org/apache/hive/beeline/TestBeeLineHistory.java b/beeline/src/test/org/apache/hive/beeline/TestBeeLineHistory.java
index 91e812f..e861976 100644
--- a/beeline/src/test/org/apache/hive/beeline/TestBeeLineHistory.java
+++ b/beeline/src/test/org/apache/hive/beeline/TestBeeLineHistory.java
@@ -40,6 +40,14 @@ public class TestBeeLineHistory {
PrintWriter writer = new PrintWriter(fileName);
writer.println("select 1;");
writer.println("select 2;");
+ writer.println("select 3;");
+ writer.println("select 4;");
+ writer.println("select 5;");
+ writer.println("select 6;");
+ writer.println("select 7;");
+ writer.println("select 8;");
+ writer.println("select 9;");
+ writer.println("select 10;");
writer.close();
}
@@ -54,7 +62,23 @@ public class TestBeeLineHistory {
beeline.dispatch("!history");
String output = os.toString("UTF-8");
int numHistories = output.split("\n").length;
- Assert.assertEquals(numHistories, 2);
+ Assert.assertEquals(numHistories, 10);
+ beeline.close();
+ }
+
+ @Test
+ public void testHistory() throws Exception {
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ PrintStream ops = new PrintStream(os);
+ BeeLine beeline = new BeeLine();
+ beeline.getOpts().setHistoryFile(fileName);
+ beeline.setOutputStream(ops);
+ beeline.getConsoleReader(null);
+ beeline.dispatch("!history");
+ String output = os.toString("UTF-8");
+ String[] tmp = output.split("\n");
+ Assert.assertTrue(tmp[0].equals("1 : select 1;"));
+ Assert.assertTrue(tmp[9].equals("10 : select 10;"));
beeline.close();
}