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

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

commit 910c6ecc8554641259f65281a159f84533a44e9d
Author: Michael Smith <[email protected]>
AuthorDate: Mon Apr 24 15:43:28 2023 -0700

    IMPALA-12094: Fix impala shell summary command
    
    Fix various quality-of-life issues with the 'summary' command:
    - update regex to correctly match query ID for handling "Query id ...
      not found" errors
    - fail the command rather than exiting the shell when 'summary' is
      called with an incorrect argument (such as 'summary 1')
    - provide a useful message rather than print an exception when 'summary
      original' is invoked with no failed queries
    
    Testing:
    - added new tests for the 'summary' command
    
    Change-Id: I7523d45b27e5e63e1f962fb1f6ebb4f0adc85213
    Reviewed-on: http://gerrit.cloudera.org:8080/19797
    Reviewed-by: Impala Public Jenkins <[email protected]>
    Tested-by: Impala Public Jenkins <[email protected]>
---
 shell/impala_shell.py                 |  8 ++++++--
 tests/shell/test_shell_commandline.py | 18 ++++++++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/shell/impala_shell.py b/shell/impala_shell.py
index 80757b4cb..c5c3dd69c 100755
--- a/shell/impala_shell.py
+++ b/shell/impala_shell.py
@@ -789,7 +789,7 @@ class ImpalaShell(cmd.Cmd, object):
       summary, failed_summary = 
self.imp_client.get_summary(self.last_query_handle)
     except RPCException as e:
       import re
-      error_pattern = re.compile("ERROR: Query id \d+:\d+ not found.")
+      error_pattern = re.compile("ERROR: Query id [a-f0-9]+:[a-f0-9]+ not 
found.")
       if error_pattern.match(e.value):
         print("Could not retrieve summary for query.", file=sys.stderr)
       else:
@@ -808,7 +808,10 @@ class ImpalaShell(cmd.Cmd, object):
     elif display_mode == QueryAttemptDisplayModes.LATEST:
       self.print_exec_summary(summary)
     elif display_mode == QueryAttemptDisplayModes.ORIGINAL:
-      self.print_exec_summary(failed_summary)
+      if failed_summary:
+        self.print_exec_summary(failed_summary)
+      else:
+        print("No failed summary found")
     else:
       raise FatalShellException("Invalid value for query summary display mode")
 
@@ -819,6 +822,7 @@ class ImpalaShell(cmd.Cmd, object):
         QueryAttemptDisplayModes.LATEST, QueryAttemptDisplayModes.ORIGINAL]:
       print("Invalid value for query attempt display mode: \'" +
           arg_mode + "\'. Valid values are [ALL | LATEST | ORIGINAL]")
+      return None
     return arg_mode
 
   def print_exec_summary(self, summary):
diff --git a/tests/shell/test_shell_commandline.py 
b/tests/shell/test_shell_commandline.py
index f469d2be3..e91ccc51f 100644
--- a/tests/shell/test_shell_commandline.py
+++ b/tests/shell/test_shell_commandline.py
@@ -457,11 +457,29 @@ class TestImpalaShell(ImpalaTestSuite):
     result_set = run_impala_shell_cmd(vector, args)
     assert "Summary not available" in result_set.stderr
 
+    args = ['-q', 'show tables; summary 1;']
+    result_set = run_impala_shell_cmd(vector, args, expect_success=False)
+    invalid_err = "Invalid value for query attempt display mode"
+    valid_opts = "Valid values are [ALL | LATEST | ORIGINAL]"
+    assert "{0}: '1'. {1}".format(invalid_err, valid_opts) in result_set.stdout
+
     # Test queries without an exchange
     args = ['-q', 'select 1; summary;']
     result_set = run_impala_shell_cmd(vector, args)
     assert "00:UNION" in result_set.stdout
 
+    args = ['-q', 'select 1; summary all;']
+    result_set = run_impala_shell_cmd(vector, args)
+    assert "00:UNION" in result_set.stdout
+
+    args = ['-q', 'select 1; summary latest;']
+    result_set = run_impala_shell_cmd(vector, args)
+    assert "00:UNION" in result_set.stdout
+
+    args = ['-q', 'select 1; summary original;']
+    result_set = run_impala_shell_cmd(vector, args)
+    assert "No failed summary found" in result_set.stdout
+
   @pytest.mark.execute_serially
   def test_queries_closed(self, vector):
     """Regression test for IMPALA-897."""

Reply via email to