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


The following commit(s) were added to refs/heads/master by this push:
     new 0ee5f8084 IMPALA-11317/IMPALA-11316/IMPALA-11315: impala-shell Python 
3 fixes
0ee5f8084 is described below

commit 0ee5f8084f1bb34fc261c729f736ac093ba59c41
Author: Joe McDonnell <[email protected]>
AuthorDate: Sat May 21 19:04:45 2022 -0700

    IMPALA-11317/IMPALA-11316/IMPALA-11315: impala-shell Python 3 fixes
    
    This fixes a few impala-shell Python 3 issues:
    1. In ImpalaShell's do_history(), the decode() call needs to be
       avoided in Python 3, because in Python 3 the cmd is already
       a string and doesn't need further decoding. (IMPALA-11315)
    2. TestImpalaShell.test_http_socket_timeout() gets a different
       error message in Python 3. It throws the "BlockingIOError"
       rather than "socker.error". (IMPALA-11316)
    3. ImpalaHttpClient.py's code to retrieve the body when
       handling an HTTP error needs to have a decode() call
       for the body. Otherwise, the body remains bytes and
       causes TestImpalaShellInteractive.test_http_interactions_extra()
       to fail. (IMPALA-11317)
    
    Testing:
     - Ran shell tests in the standard way
     - Ran shell tests with the impala-shell executable coming from
       a Python 3 virtualenv using the PyPi package
    
    Change-Id: Ie58380a17d7e011f4ce96b27d34717509a0b80a6
    Reviewed-on: http://gerrit.cloudera.org:8080/18556
    Reviewed-by: Impala Public Jenkins <[email protected]>
    Reviewed-by: Wenzhe Zhou <[email protected]>
    Tested-by: Impala Public Jenkins <[email protected]>
---
 shell/ImpalaHttpClient.py             |  2 +-
 shell/impala_shell.py                 |  5 ++++-
 tests/shell/test_shell_commandline.py | 11 ++++++++---
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/shell/ImpalaHttpClient.py b/shell/ImpalaHttpClient.py
index 9903501bd..5d7de079c 100644
--- a/shell/ImpalaHttpClient.py
+++ b/shell/ImpalaHttpClient.py
@@ -362,5 +362,5 @@ class ImpalaHttpClient(TTransportBase):
     if self.code >= 300:
       # Report any http response code that is not 1XX (informational response) 
or
       # 2XX (successful).
-      body = self.readBody()
+      body = self.readBody().decode('utf-8')
       raise HttpError(self.code, self.message, body, self.headers)
diff --git a/shell/impala_shell.py b/shell/impala_shell.py
index 50ad5eaa1..6d7b1e59d 100755
--- a/shell/impala_shell.py
+++ b/shell/impala_shell.py
@@ -1503,7 +1503,10 @@ class ImpalaShell(cmd.Cmd, object):
     if self.readline and self.readline.get_current_history_length() > 0:
       for index in xrange(1, self.readline.get_current_history_length() + 1):
         cmd = self.readline.get_history_item(index)
-        print('[%d]: %s' % (index, cmd.decode('utf-8', 'replace')), 
file=sys.stderr)
+        if sys.version_info.major == 2:
+          print('[%d]: %s' % (index, cmd.decode('utf-8', 'replace')), 
file=sys.stderr)
+        else:
+          print('[%d]: %s' % (index, cmd), file=sys.stderr)
     else:
       print(READLINE_UNAVAILABLE_ERROR, file=sys.stderr)
 
diff --git a/tests/shell/test_shell_commandline.py 
b/tests/shell/test_shell_commandline.py
index 65a96515d..3d698fb8a 100644
--- a/tests/shell/test_shell_commandline.py
+++ b/tests/shell/test_shell_commandline.py
@@ -1206,9 +1206,14 @@ class TestImpalaShell(ImpalaTestSuite):
     args = ['--quiet', '-B', '--query', 'select 0;']
     result = run_impala_shell_cmd(vector, args + ['--http_socket_timeout_s=0'],
                                   expect_success=False)
-    expected_err = ("Caught exception [Errno 115] Operation now in progress, "
-                   "type=<class 'socket.error'> in OpenSession. Num remaining 
tries: 3")
-    assert result.stderr.splitlines()[0] == expected_err
+    expected_err_py2 = (
+      "Caught exception [Errno 115] Operation now in progress, "
+      "type=<class 'socket.error'> in OpenSession. Num remaining tries: 3")
+    expected_err_py3 = (
+      "Caught exception [Errno 115] Operation now in progress, "
+      "type=<class 'BlockingIOError'> in OpenSession. Num remaining tries: 3")
+    actual_err = result.stderr.splitlines()[0]
+    assert actual_err == expected_err_py2 or actual_err == expected_err_py3
 
     # Test http_socket_timeout_s=-1, expect errors
     result = run_impala_shell_cmd(vector, args + 
['--http_socket_timeout_s=-1'],

Reply via email to