diff --git a/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java b/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java index 21675dcd6c..60c740a286 100644 --- a/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java +++ b/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java @@ -68,6 +68,7 @@ private final BeeLine beeLine; private boolean autosave = false; private boolean silent = false; + private Boolean report = null; private boolean color = false; private boolean showHeader = true; private boolean escapeCRLF = false; @@ -571,6 +572,14 @@ public boolean isSilent() { return silent; } + public void setReport(boolean report) { + this.report = report; + } + + public Boolean isReport() { + return report; + } + public void setAutosave(boolean autosave) { this.autosave = autosave; } diff --git a/beeline/src/java/org/apache/hive/beeline/Commands.java b/beeline/src/java/org/apache/hive/beeline/Commands.java index fd0af2ca0c..8f47323700 100644 --- a/beeline/src/java/org/apache/hive/beeline/Commands.java +++ b/beeline/src/java/org/apache/hive/beeline/Commands.java @@ -1026,8 +1026,10 @@ private boolean executeInternal(String sql, boolean call) { int count = beeLine.print(rs); long end = System.currentTimeMillis(); - beeLine.info( - beeLine.loc("rows-selected", count) + " " + beeLine.locElapsedTime(end - start)); + if (showReport()) { + beeLine.output(beeLine.loc("rows-selected", count) + " " + beeLine.locElapsedTime(end - start), + true, beeLine.getErrorStream()); + } } finally { if (logThread != null) { logThread.join(DEFAULT_QUERY_PROGRESS_THREAD_TIMEOUT); @@ -1043,8 +1045,11 @@ private boolean executeInternal(String sql, boolean call) { } else { int count = stmnt.getUpdateCount(); long end = System.currentTimeMillis(); - beeLine.info( - beeLine.loc("rows-affected", count) + " " + beeLine.locElapsedTime(end - start)); + + if (showReport()) { + beeLine.output(beeLine.loc("rows-affected", count) + " " + beeLine.locElapsedTime(end - start), + true, beeLine.getErrorStream()); + } } } finally { if (logThread != null) { @@ -1070,6 +1075,13 @@ private boolean executeInternal(String sql, boolean call) { return true; } + private boolean showReport() { + if (beeLine.getOpts().isReport() != null) { + return beeLine.getOpts().isReport(); + } + return !beeLine.getOpts().isSilent(); + } + /* * Check if the input line is a multi-line command which needs to read further */ diff --git a/beeline/src/main/resources/BeeLine.properties b/beeline/src/main/resources/BeeLine.properties index 12f31a4463..d4b8f17331 100644 --- a/beeline/src/main/resources/BeeLine.properties +++ b/beeline/src/main/resources/BeeLine.properties @@ -189,6 +189,7 @@ cmd-usage: Usage: java org.apache.hive.cli.beeline.BeeLine \n \ \ --maxWidth=MAXWIDTH the maximum width of the terminal\n \ \ --maxColumnWidth=MAXCOLWIDTH the maximum width to use when displaying columns\n \ \ --silent=[true/false] be more silent\n \ +\ --report=[true/false] show number of rows and execution time after query execution\n \ \ --autosave=[true/false] automatically save preferences\n \ \ --outputformat=[table/vertical/csv2/tsv2/dsv/csv/tsv] format mode for result display\n \ \ Note that csv, and tsv are deprecated - use csv2, tsv2 instead\n \ diff --git a/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java b/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java index c9ff066a53..c632dd3d12 100644 --- a/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java +++ b/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java @@ -368,4 +368,17 @@ public void testFileParam() throws Exception { Assert.assertTrue(bl.getOpts().getScriptFile().equals("hdfs://myscript")); } + /** + * Test the report parameter option. + * @throws Exception + */ + @Test + public void testReport() throws Exception { + TestBeeline bl = new TestBeeline(); + String args[] = new String[] {"--report=true"}; + Assert.assertEquals(0, bl.initArgs(args)); + Assert.assertTrue(bl.getOpts().isReport()); + bl.close(); + } + } diff --git a/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java b/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java index 51e491c9ca..18b5410dc4 100644 --- a/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java +++ b/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java @@ -1069,6 +1069,27 @@ public void testBeelineWithForce() throws Throwable { testScriptFile(SCRIPT_TEXT, argList, OutStream.ERR, EXPECTED_PATTERN, true); } + @Test + public void testBeelineWithSilentAndReport() throws Throwable { + final String SCRIPT_TEXT = "drop table if exists new_table;\n create table new_table(foo int, bar string);\n " + + "desc new_table;\n"; + final String EXPECTED_PATTERN = "2 rows selected"; + List argList = getBaseArgs(miniHS2.getBaseJdbcURL()); + argList.add("--silent=true"); + argList.add("--report=true"); + testScriptFile(SCRIPT_TEXT, argList, OutStream.ERR, EXPECTED_PATTERN, true); + } + + @Test + public void testBeelineWithSilent() throws Throwable { + final String SCRIPT_TEXT = "drop table if exists new_table;\n create table new_table(foo int, bar string);\n " + + "desc new_table;\n"; + final String EXPECTED_PATTERN = "2 rows selected"; + List argList = getBaseArgs(miniHS2.getBaseJdbcURL()); + argList.add("--silent=true"); + testScriptFile(SCRIPT_TEXT, argList, OutStream.ERR, EXPECTED_PATTERN, false); + } + private static class Tuple { final K pattern; final boolean shouldMatch;