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

sankarh pushed a commit to branch branch-3
in repository https://gitbox.apache.org/repos/asf/hive.git


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

commit 5cbf98b0f93a4d07a9dae8cd370783c4ee411525
Author: Aman Raj <104416558+amanraj2...@users.noreply.github.com>
AuthorDate: Wed Aug 23 14:52:32 2023 +0530

    HIVE-27613: Backport of HIVE-22204: Beeline option to show/not show 
execution report (Jesus Camacho Rodriguez, reviewed by Ashutosh Chauhan)
    
    Signed-off-by: Sankar Hariappan <sank...@apache.org>
    Closes (#4592)
---
 .../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 | 28 ++++++++++++++++++++++
 .../apache/hive/beeline/TestBeeLineWithArgs.java   | 21 ++++++++++++++++
 5 files changed, 75 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 3877b5cc30f..5967b4d7bc0 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;
@@ -569,6 +570,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 f14564a81ac..425ea8b53c5 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) {
@@ -1068,6 +1073,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 c41b3ed637e..a4e342d089b 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 818ff73a3ba..66e18737fb0 100644
--- a/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java
+++ b/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java
@@ -357,4 +357,32 @@ public class TestBeelineArgParsing {
     Assert.assertTrue(bl.getOpts().getMaxHistoryRows() == 100);
     bl.close();
   }
+
+  /**
+   * Test the file parameter option
+   * @throws Exception
+   */
+  @Test
+  public void testFileParam() throws Exception {
+    TestBeeline bl = new TestBeeline();
+    String args[] = new String[] {"-u", "url", "-n", "name",
+        "-p", "password", "-d", "driver", "-f", "hdfs://myscript"};
+    Assert.assertEquals(0, bl.initArgs(args));
+    Assert.assertTrue(bl.connectArgs.equals("url name password driver"));
+    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 51e491c9ca6..18b5410dc49 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;

Reply via email to