You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by jc...@apache.org on 2019/09/14 18:55:55 UTC

[hive] branch master updated: HIVE-22204: Beeline option to show/not show execution report (Jesus Camacho Rodriguez, reviewed by Ashutosh Chauhan)

This is an automated email from the ASF dual-hosted git repository.

jcamacho pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git


The following commit(s) were added to refs/heads/master by this push:
     new ff81408  HIVE-22204: Beeline option to show/not show execution report (Jesus Camacho Rodriguez, reviewed by Ashutosh Chauhan)
ff81408 is described below

commit ff814080b202f91457248785b8b1654253081ea9
Author: Jesus Camacho Rodriguez <jc...@apache.org>
AuthorDate: Fri Sep 13 16:16:12 2019 -0700

    HIVE-22204: Beeline option to show/not show execution report (Jesus Camacho Rodriguez, reviewed by Ashutosh Chauhan)
---
 .../java/org/apache/hive/beeline/BeeLineOpts.java   |  9 +++++++++
 .../src/java/org/apache/hive/beeline/Commands.java  | 20 ++++++++++++++++----
 beeline/src/main/resources/BeeLine.properties       |  1 +
 .../apache/hive/beeline/TestBeelineArgParsing.java  | 13 +++++++++++++
 .../apache/hive/beeline/TestBeeLineWithArgs.java    | 21 +++++++++++++++++++++
 5 files changed, 60 insertions(+), 4 deletions(-)

diff --git a/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java b/beeline/src/java/org/apache/hive/beeline/BeeLineOpts.java
index 21675dc..60c740a 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 @@ public class BeeLineOpts implements Completer {
   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 class BeeLineOpts implements Completer {
     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 fd0af2c..8f47323 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 @@ public class Commands {
               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 @@ public class Commands {
         } 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 @@ public class Commands {
     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 12f31a4..d4b8f17 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 c9ff066..c632dd3 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 class TestBeelineArgParsing {
     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 51e491c..18b5410 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 class TestBeeLineWithArgs {
     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<String> 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<String> argList = getBaseArgs(miniHS2.getBaseJdbcURL());
+    argList.add("--silent=true");
+    testScriptFile(SCRIPT_TEXT, argList, OutStream.ERR, EXPECTED_PATTERN, false);
+  }
+
   private static class Tuple<K> {
     final K pattern;
     final boolean shouldMatch;