You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by jo...@apache.org on 2023/02/28 17:12:50 UTC

[impala] 03/06: IMPALA-11952 (part 1): Fix except syntax

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 c71de994b07c3863104b7626c6fd15a5650c066c
Author: Joe McDonnell <jo...@cloudera.com>
AuthorDate: Sun Feb 26 13:12:47 2023 -0800

    IMPALA-11952 (part 1): Fix except syntax
    
    Python 3 does not support this old except syntax:
    
    except Exception, e:
    
    Instead, it needs to be:
    
    except Exception as e:
    
    This uses impala-futurize to fix all locations of
    the old syntax.
    
    Testing:
     - The check-python-syntax.sh no longer shows errors
       for except syntax.
    
    Change-Id: I1737281a61fa159c8d91b7d4eea593177c0bd6c9
    Reviewed-on: http://gerrit.cloudera.org:8080/19551
    Reviewed-by: Joe McDonnell <jo...@cloudera.com>
    Reviewed-by: Michael Smith <mi...@cloudera.com>
    Tested-by: Michael Smith <mi...@cloudera.com>
---
 bin/bootstrap_toolchain.py                       |  2 +-
 bin/generate_xml_config.py                       |  2 +-
 bin/get_code_size.py                             |  2 +-
 bin/start-impala-cluster.py                      |  2 +-
 docker/monitor.py                                |  2 +-
 infra/deploy/deploy.py                           |  2 +-
 testdata/common/cgroups.py                       |  2 +-
 tests/beeswax/impala_beeswax.py                  | 10 +++++-----
 tests/common/impala_cluster.py                   |  4 ++--
 tests/common/impala_service.py                   |  6 +++---
 tests/common/impala_test_suite.py                |  8 ++++----
 tests/custom_cluster/test_coordinators.py        |  4 ++--
 tests/custom_cluster/test_hdfs_timeout.py        |  2 +-
 tests/custom_cluster/test_hs2_fault_injection.py |  6 +++---
 tests/custom_cluster/test_local_catalog.py       |  2 +-
 tests/custom_cluster/test_mem_reservations.py    |  2 +-
 tests/custom_cluster/test_query_expiration.py    |  6 +++---
 tests/custom_cluster/test_query_retries.py       | 10 +++++-----
 tests/custom_cluster/test_restart_services.py    | 12 ++++++------
 tests/metadata/test_ddl.py                       |  2 +-
 tests/metadata/test_hdfs_permissions.py          |  4 ++--
 tests/performance/query_exec_functions.py        | 10 +++++-----
 tests/query_test/test_beeswax.py                 |  4 ++--
 tests/query_test/test_decimal_queries.py         |  6 +++---
 tests/query_test/test_insert.py                  |  2 +-
 tests/query_test/test_nested_types.py            |  6 +++---
 tests/query_test/test_partitioning.py            |  2 +-
 tests/query_test/test_query_mem_limit.py         |  2 +-
 tests/query_test/test_udfs.py                    |  6 +++---
 tests/shell/test_shell_commandline.py            |  4 ++--
 tests/statestore/test_statestore.py              | 12 ++++++------
 tests/unittests/test_result_verifier.py          |  4 ++--
 32 files changed, 75 insertions(+), 75 deletions(-)

diff --git a/bin/bootstrap_toolchain.py b/bin/bootstrap_toolchain.py
index 7e8371a4d..457625d19 100755
--- a/bin/bootstrap_toolchain.py
+++ b/bin/bootstrap_toolchain.py
@@ -138,7 +138,7 @@ def wget_and_unpack_package(download_path, file_name, destination, wget_no_clobb
         cmd.append("--no-clobber")
       check_output(cmd)
       break
-    except Exception, e:
+    except Exception as e:
       if attempt == NUM_ATTEMPTS:
         raise
       logging.error("Download failed; retrying after sleep: " + str(e))
diff --git a/bin/generate_xml_config.py b/bin/generate_xml_config.py
index af9c2e5c4..915e3e276 100755
--- a/bin/generate_xml_config.py
+++ b/bin/generate_xml_config.py
@@ -84,7 +84,7 @@ def dump_config(d, source_path, out):
       if isinstance(v, int):
         v = str(v)
       v_new = _substitute_env_vars(v)
-    except KeyError, e:
+    except KeyError as e:
       raise Exception("failed environment variable substitution for value {k}: {e}"
                       .format(k=k, e=e))
     print >>out, """\
diff --git a/bin/get_code_size.py b/bin/get_code_size.py
index 53e19485b..9a2e78298 100755
--- a/bin/get_code_size.py
+++ b/bin/get_code_size.py
@@ -29,7 +29,7 @@ def get_bin_size_data(file):
   data = ""
   try:
     data = subprocess.check_output(["size", "-B", "-t", file], stderr=subprocess.STDOUT)
-  except Exception, e:
+  except Exception as e:
     data = e.output
 
   res = re.split(r'\s+', data.split("\n")[-2])
diff --git a/bin/start-impala-cluster.py b/bin/start-impala-cluster.py
index d4295a165..b1e94545e 100755
--- a/bin/start-impala-cluster.py
+++ b/bin/start-impala-cluster.py
@@ -846,7 +846,7 @@ if __name__ == "__main__":
     # Check for the cluster to be ready.
     impala_cluster.wait_until_ready(expected_cluster_size,
         expected_cluster_size - expected_catalog_delays)
-  except Exception, e:
+  except Exception as e:
     LOG.exception("Error starting cluster")
     sys.exit(1)
 
diff --git a/docker/monitor.py b/docker/monitor.py
index 5eefe5c9b..530c63c7c 100644
--- a/docker/monitor.py
+++ b/docker/monitor.py
@@ -163,7 +163,7 @@ class ContainerMonitor(object):
     try:
       statcontents = file(os.path.join(dirname, stat)).read()
       return statcontents.replace("\n", " ").strip()
-    except IOError, e:
+    except IOError as e:
       # Ignore errors; cgroup can disappear on us.
       logging.warning("Ignoring exception reading cgroup. " +
                       "This can happen if container just exited. " + str(e))
diff --git a/infra/deploy/deploy.py b/infra/deploy/deploy.py
index 9fcfb2863..1665e5182 100644
--- a/infra/deploy/deploy.py
+++ b/infra/deploy/deploy.py
@@ -339,7 +339,7 @@ def transform_port(rcg_name, rcg_config_dict, rcg_config_name):
                         (rcg_config_name, rcg_name,))
     try:
         val_int = int(val)
-    except ValueError, e:
+    except ValueError as e:
         raise Exception("Could not convert %s config (%s) for rcg %s into integer" %
                         (rcg_config_name, val, rcg_name))
 
diff --git a/testdata/common/cgroups.py b/testdata/common/cgroups.py
index f7f90a358..c313b563f 100755
--- a/testdata/common/cgroups.py
+++ b/testdata/common/cgroups.py
@@ -73,7 +73,7 @@ def create_impala_cgroup_path(instance_num):
   cgroup_path = os.path.join(parent_cgroup, ("impala-%s" % instance_num))
   try:
     os.makedirs(cgroup_path)
-  except OSError, ex:
+  except OSError as ex:
     if ex.errno == errno.EEXIST and os.path.isdir(cgroup_path):
         pass
     else: raise
diff --git a/tests/beeswax/impala_beeswax.py b/tests/beeswax/impala_beeswax.py
index a3fae9da7..3edfb2584 100644
--- a/tests/beeswax/impala_beeswax.py
+++ b/tests/beeswax/impala_beeswax.py
@@ -160,7 +160,7 @@ class ImpalaBeeswaxClient(object):
       protocol = TBinaryProtocol.TBinaryProtocolAccelerated(self.transport)
       self.imp_service = ImpalaService.Client(protocol)
       self.connected = True
-    except Exception, e:
+    except Exception as e:
       raise ImpalaBeeswaxException(self.__build_error_message(e), e)
 
   def close_connection(self):
@@ -518,12 +518,12 @@ class ImpalaBeeswaxClient(object):
       raise ImpalaBeeswaxException("Not connected", None)
     try:
       return rpc()
-    except BeeswaxService.BeeswaxException, b:
+    except BeeswaxService.BeeswaxException as b:
       raise ImpalaBeeswaxException(self.__build_error_message(b), b)
-    except TTransportException, e:
+    except TTransportException as e:
       self.connected = False
       raise ImpalaBeeswaxException(self.__build_error_message(e), e)
-    except TApplicationException, t:
+    except TApplicationException as t:
       raise ImpalaBeeswaxException(self.__build_error_message(t), t)
-    except Exception, u:
+    except Exception as u:
       raise ImpalaBeeswaxException(self.__build_error_message(u), u)
diff --git a/tests/common/impala_cluster.py b/tests/common/impala_cluster.py
index 89167b7dd..8e0860fec 100644
--- a/tests/common/impala_cluster.py
+++ b/tests/common/impala_cluster.py
@@ -597,10 +597,10 @@ def find_user_processes(binaries):
       binary_name = os.path.basename(cmdline[0])
       if binary_name in binaries:
         yield binary_name, process
-    except KeyError, e:
+    except KeyError as e:
       if "uid not found" not in str(e):
         raise
-    except psutil.NoSuchProcess, e:
+    except psutil.NoSuchProcess as e:
       # Ignore the case when a process no longer exists.
       pass
 
diff --git a/tests/common/impala_service.py b/tests/common/impala_service.py
index b8e5ca7d9..822e361f6 100644
--- a/tests/common/impala_service.py
+++ b/tests/common/impala_service.py
@@ -120,7 +120,7 @@ class BaseImpalaService(object):
       value = None
       try:
         value = self.get_metric_value(metric_name)
-      except Exception, e:
+      except Exception as e:
         LOG.error(e)
 
       # if allow_greater is True we wait until the metric value becomes >= the expected
@@ -359,7 +359,7 @@ class ImpaladService(BaseImpalaService):
       try:
         value = self.get_num_known_live_backends(timeout=1, interval=interval,
             include_shutting_down=include_shutting_down)
-      except Exception, e:
+      except Exception as e:
         LOG.error(e)
       if value == expected_value:
         LOG.info("num_known_live_backends has reached value: %s" % value)
@@ -461,7 +461,7 @@ class ImpaladService(BaseImpalaService):
       transport.open()
       transport.close()
       return True
-    except Exception, e:
+    except Exception as e:
       LOG.info(e)
       return False
 
diff --git a/tests/common/impala_test_suite.py b/tests/common/impala_test_suite.py
index 0a605a0d7..98d7ba164 100644
--- a/tests/common/impala_test_suite.py
+++ b/tests/common/impala_test_suite.py
@@ -323,13 +323,13 @@ class ImpalaTestSuite(BaseTestSuite):
     cls.hs2_client = None
     try:
       cls.hs2_client = cls.create_impala_client(protocol='hs2')
-    except Exception, e:
+    except Exception as e:
       # HS2 connection can fail for benign reasons, e.g. running with unsupported auth.
       LOG.info("HS2 connection setup failed, continuing...: {0}".format(e))
     cls.hs2_http_client = None
     try:
       cls.hs2_http_client = cls.create_impala_client(protocol='hs2-http')
-    except Exception, e:
+    except Exception as e:
       # HS2 HTTP connection can fail for benign reasons, e.g. running with unsupported
       # auth.
       LOG.info("HS2 HTTP connection setup failed, continuing...: {0}".format(e))
@@ -882,7 +882,7 @@ class ImpalaTestSuite(BaseTestSuite):
     result = None
     try:
       result = cls.__execute_query(impalad_client, query, query_options, user)
-    except Exception, e:
+    except Exception as e:
       return e
 
     assert not result.success, "No failure encountered for query %s" % query
@@ -1201,7 +1201,7 @@ class ImpalaTestSuite(BaseTestSuite):
         self.client.execute("describe `{db_name}`.`{table_name}`".format(
                             db_name=db_name, table_name=table_name))
         return
-      except Exception, ex:
+      except Exception as ex:
         print str(ex)
         time.sleep(0.2)
         continue
diff --git a/tests/custom_cluster/test_coordinators.py b/tests/custom_cluster/test_coordinators.py
index 5b816f424..635892da5 100644
--- a/tests/custom_cluster/test_coordinators.py
+++ b/tests/custom_cluster/test_coordinators.py
@@ -48,7 +48,7 @@ class TestCoordinators(CustomClusterTestSuite):
     beeswax_client = None
     try:
       beeswax_client = worker.service.create_beeswax_client()
-    except Exception, e:
+    except Exception as e:
       LOG.info("Caught exception {0}".format(e))
     finally:
       assert beeswax_client is None
@@ -56,7 +56,7 @@ class TestCoordinators(CustomClusterTestSuite):
     hs2_client = None
     try:
       hs2_client = worker.service.create_hs2_client()
-    except Exception, e:
+    except Exception as e:
       LOG.info("Caught exception {0}".format(e))
     finally:
       assert hs2_client is None
diff --git a/tests/custom_cluster/test_hdfs_timeout.py b/tests/custom_cluster/test_hdfs_timeout.py
index 9e9b84a96..fb2d3e38e 100644
--- a/tests/custom_cluster/test_hdfs_timeout.py
+++ b/tests/custom_cluster/test_hdfs_timeout.py
@@ -71,7 +71,7 @@ class TestHdfsTimeouts(CustomClusterTestSuite):
       result = self.execute_query("select count(*) from functional.alltypes",
           vector=vector)
       end_time = time.time()
-    except Exception, e:
+    except Exception as e:
       ex = e
     finally:
       end_time = time.time()
diff --git a/tests/custom_cluster/test_hs2_fault_injection.py b/tests/custom_cluster/test_hs2_fault_injection.py
index 47107ba74..0b3f8e7b4 100644
--- a/tests/custom_cluster/test_hs2_fault_injection.py
+++ b/tests/custom_cluster/test_hs2_fault_injection.py
@@ -274,7 +274,7 @@ class TestHS2FaultInjection(CustomClusterTestSuite):
     query_handle = None
     try:
       query_handle = self.custom_hs2_http_client.execute_query('select 1', {})
-    except Exception, e:
+    except Exception as e:
       assert str(e) == 'HTTP code 502: Injected Fault'
     assert query_handle is None
     output = capsys.readouterr()[1].splitlines()
@@ -293,7 +293,7 @@ class TestHS2FaultInjection(CustomClusterTestSuite):
     try:
       for rows in rows_fetched:
         num_rows += 1
-    except Exception, e:
+    except Exception as e:
       assert str(e) == 'HTTP code 502: Injected Fault'
     assert num_rows is None
     self.close_query(query_handle)
@@ -315,7 +315,7 @@ class TestHS2FaultInjection(CustomClusterTestSuite):
     (num_rows, num_row_errors) = None, None
     try:
       (num_rows, num_row_errors) = self.custom_hs2_http_client.close_dml(query_handle)
-    except Exception, e:
+    except Exception as e:
       assert str(e) == 'HTTP code 502: Injected Fault'
     assert num_rows is None
     assert num_row_errors is None
diff --git a/tests/custom_cluster/test_local_catalog.py b/tests/custom_cluster/test_local_catalog.py
index 53d535ec6..78eccb4ae 100644
--- a/tests/custom_cluster/test_local_catalog.py
+++ b/tests/custom_cluster/test_local_catalog.py
@@ -149,7 +149,7 @@ class TestCompactCatalogUpdates(CustomClusterTestSuite):
           err = self.execute_query_expect_failure(client, "select * from %s" % view)
           assert "Could not resolve table reference" in str(err)
           break
-        except Exception, e:
+        except Exception as e:
           assert attempt < NUM_ATTEMPTS - 1, str(e)
         time.sleep(1)
 
diff --git a/tests/custom_cluster/test_mem_reservations.py b/tests/custom_cluster/test_mem_reservations.py
index bf1641b2c..6365ec126 100644
--- a/tests/custom_cluster/test_mem_reservations.py
+++ b/tests/custom_cluster/test_mem_reservations.py
@@ -87,7 +87,7 @@ class TestMemReservations(CustomClusterTestSuite):
             result = client.execute(self.query)
             assert result.success
             assert len(result.data) == 1
-        except Exception, e:
+        except Exception as e:
           self.error = str(e)
         finally:
           client.close()
diff --git a/tests/custom_cluster/test_query_expiration.py b/tests/custom_cluster/test_query_expiration.py
index 4324b532e..d6b0011fd 100644
--- a/tests/custom_cluster/test_query_expiration.py
+++ b/tests/custom_cluster/test_query_expiration.py
@@ -127,7 +127,7 @@ class TestQueryExpiration(CustomClusterTestSuite):
     for handle in handles:
       try:
         client.close_query(handle)
-      except Exception, e:
+      except Exception as e:
         # We fetched from some cancelled handles above, which unregistered the queries.
         assert 'Invalid or unknown query handle' in str(e)
 
@@ -172,7 +172,7 @@ class TestQueryExpiration(CustomClusterTestSuite):
     try:
       client.fetch(query, handle)
       assert False
-    except Exception, e:
+    except Exception as e:
       assert re.search(exception_regex, str(e))
 
   def __expect_client_state(self, client, handle, expected_state, timeout=0.1):
@@ -222,7 +222,7 @@ class TestQueryExpiration(CustomClusterTestSuite):
         try:
           result = self.client.execute("SELECT SLEEP(2500)")
           assert "Expected to hit time limit"
-        except Exception, e:
+        except Exception as e:
           self.exception = e
 
     class NonExpiringTimeLimitThread(threading.Thread):
diff --git a/tests/custom_cluster/test_query_retries.py b/tests/custom_cluster/test_query_retries.py
index 469bb326f..1a5f5efdb 100644
--- a/tests/custom_cluster/test_query_retries.py
+++ b/tests/custom_cluster/test_query_retries.py
@@ -403,7 +403,7 @@ class TestQueryRetries(CustomClusterTestSuite):
     try:
       self.client.fetch(self._shuffle_heavy_query, handle)
       assert False
-    except ImpalaBeeswaxException, e:
+    except ImpalaBeeswaxException as e:
       assert "Admission for query exceeded timeout 60000ms in pool default-pool." \
           in str(e)
       assert "Queued reason: Waiting for executors to start. Only DDL queries and " \
@@ -467,7 +467,7 @@ class TestQueryRetries(CustomClusterTestSuite):
     try:
       self.client.fetch(self._shuffle_heavy_query, handle)
       assert False
-    except ImpalaBeeswaxException, e:
+    except ImpalaBeeswaxException as e:
       assert "Max retry limit was hit. Query was retried 1 time(s)." in str(e)
 
     # Assert that the killed impalad shows up in the list of blacklisted executors from
@@ -724,7 +724,7 @@ class TestQueryRetries(CustomClusterTestSuite):
     try:
       self.client.fetch(query, handle)
       assert False
-    except Exception, e:
+    except Exception as e:
         assert "Cancelled" in str(e)
     self.__validate_memz()
 
@@ -874,7 +874,7 @@ class TestQueryRetries(CustomClusterTestSuite):
     try:
       self.client.fetch(query, handle)
       assert False
-    except Exception, e:
+    except Exception as e:
         assert "expired due to client inactivity" in str(e)
 
     # Assert that the impalad metrics show one expired query.
@@ -907,7 +907,7 @@ class TestQueryRetries(CustomClusterTestSuite):
     # error.
     try:
       client.fetch(query, handle)
-    except Exception, e:
+    except Exception as e:
       assert "Client session expired" in str(e)
 
     # Assert that the impalad metrics show one expired session.
diff --git a/tests/custom_cluster/test_restart_services.py b/tests/custom_cluster/test_restart_services.py
index a97f7e857..fb1564943 100644
--- a/tests/custom_cluster/test_restart_services.py
+++ b/tests/custom_cluster/test_restart_services.py
@@ -62,7 +62,7 @@ class TestRestart(CustomClusterTestSuite):
       try:
         cursor.execute("describe database functional")
         return
-      except HiveServer2Error, e:
+      except HiveServer2Error as e:
         assert "AnalysisException: Database does not exist: functional" in e.message,\
                "Unexpected exception: " + e.message
         sleep(1)
@@ -178,7 +178,7 @@ class TestRestart(CustomClusterTestSuite):
       try:
         query = "alter table join_aa add columns (age" + str(i) + " int)"
         self.execute_query_async(query)
-      except Exception, e:
+      except Exception as e:
         LOG.info(str(e))
       if i == 5:
         self.cluster.catalogd.restart()
@@ -204,7 +204,7 @@ class TestRestart(CustomClusterTestSuite):
       try:
         query = "alter table join_aa add columns (age" + str(i) + " int)"
         self.execute_query_async(query, query_options)
-      except Exception, e:
+      except Exception as e:
         LOG.info(str(e))
       if i == 5:
         self.cluster.catalogd.restart()
@@ -256,7 +256,7 @@ class TestRestart(CustomClusterTestSuite):
       try:
         query = "alter table join_aa add columns (age" + str(i) + " int)"
         self.execute_query_async(query)
-      except Exception, e:
+      except Exception as e:
         LOG.info(str(e))
       if i == 5:
         self.cluster.catalogd.restart()
@@ -666,7 +666,7 @@ class TestGracefulShutdown(CustomClusterTestSuite, HS2TestSuite):
     def expect_beeswax_shutdown_error(fn):
       try:
         fn()
-      except ImpalaBeeswaxException, e:
+      except ImpalaBeeswaxException as e:
         assert SHUTDOWN_ERROR_PREFIX in str(e)
     expect_beeswax_shutdown_error(lambda: self.client.execute("select 1"))
     expect_beeswax_shutdown_error(lambda: self.client.execute_async("select 1"))
@@ -741,7 +741,7 @@ class TestGracefulShutdown(CustomClusterTestSuite, HS2TestSuite):
     try:
       self.client.fetch(query, handle)
       assert False, "Expected query to fail"
-    except Exception, e:
+    except Exception as e:
       assert 'Failed due to unreachable impalad(s)' in str(e)
 
   @pytest.mark.execute_serially
diff --git a/tests/metadata/test_ddl.py b/tests/metadata/test_ddl.py
index d8ecbcad5..06ef7fbc7 100644
--- a/tests/metadata/test_ddl.py
+++ b/tests/metadata/test_ddl.py
@@ -570,7 +570,7 @@ class TestDdlStatements(TestDdlBase):
             result = self.execute_query_expect_success(
                 client, "describe formatted %s" % view_name)
             exp_line = [l for l in result.data if 'View Expanded' in l][0]
-          except ImpalaBeeswaxException, e:
+          except ImpalaBeeswaxException as e:
             # In non-SYNC_DDL tests, it's OK to get a "missing view" type error
             # until the metadata propagates.
             exp_line = "Exception: %s" % e
diff --git a/tests/metadata/test_hdfs_permissions.py b/tests/metadata/test_hdfs_permissions.py
index 2ff4e1e6a..766fdfcfc 100644
--- a/tests/metadata/test_hdfs_permissions.py
+++ b/tests/metadata/test_hdfs_permissions.py
@@ -64,7 +64,7 @@ class TestHdfsPermissions(ImpalaTestSuite):
     try:
       self.client.execute('insert into table %s select 1' % TEST_TBL)
       assert False, 'Expected INSERT INTO read-only table to fail'
-    except Exception, e:
+    except Exception as e:
       assert re.search('does not have WRITE access to HDFS location: .*/read_only_tbl',
                        str(e))
     # Should still be able to query this table without any errors.
@@ -85,7 +85,7 @@ class TestHdfsPermissions(ImpalaTestSuite):
           'insert into table functional_seq.alltypes '
           'partition(year, month) select * from functional.alltypes limit 0')
       assert False, 'Expected INSERT INTO read-only partition to fail'
-    except Exception, e:
+    except Exception as e:
       assert re.search(
           'does not have WRITE access to HDFS location: .*/alltypes_seq',
           str(e))
diff --git a/tests/performance/query_exec_functions.py b/tests/performance/query_exec_functions.py
index 352c9a737..2bd2953f1 100644
--- a/tests/performance/query_exec_functions.py
+++ b/tests/performance/query_exec_functions.py
@@ -47,7 +47,7 @@ def get_hs2_hive_cursor(hiveserver, user=None, use_kerberos=False,
 
     cursor = conn.cursor(configuration=execOptions)
     LOG.info("Connected to {0}:{1}".format(host, port))
-  except Exception, e:
+  except Exception as e:
     LOG.error("Error Connecting: {0}".format(str(e)))
   return cursor
 
@@ -102,7 +102,7 @@ def get_hs2_impala_cursor(impalad, use_kerberos=False, database=None):
         auth_mechanism="GSSAPI" if use_kerberos else "NOSASL")
     cursor = conn.cursor()
     LOG.info("Connected to {0}:{1}".format(host, port))
-  except Exception, e:
+  except Exception as e:
     LOG.error("Error connecting: {0}".format(str(e)))
   return cursor
 
@@ -165,7 +165,7 @@ def establish_beeswax_connection(query_config):
     # Set the exec options.
     client.set_query_options(query_config.exec_options)
     LOG.info("Connected to %s" % query_config.impalad)
-  except Exception, e:
+  except Exception as e:
     LOG.error("Error connecting: {0}".format(str(e)))
   return client
 
@@ -195,7 +195,7 @@ def execute_using_impala_beeswax(query, query_config):
   result = None
   try:
     result = client.execute(query.query_str)
-  except Exception, e:
+  except Exception as e:
     LOG.error(e)
     exec_result.query_error = str(e)
   finally:
@@ -284,7 +284,7 @@ def run_query_capture_results(cmd, query, exit_on_error):
   start_time = datetime.now()
   try:
     rc, stdout, stderr = exec_process(cmd)
-  except Exception, e:
+  except Exception as e:
     LOG.error('Error while executing query command: %s' % e)
     exec_result.query_error = str(e)
     # TODO: Should probably save the start time and query string for failed queries.
diff --git a/tests/query_test/test_beeswax.py b/tests/query_test/test_beeswax.py
index 037a4a344..2887d1c23 100644
--- a/tests/query_test/test_beeswax.py
+++ b/tests/query_test/test_beeswax.py
@@ -85,7 +85,7 @@ class TestBeeswax(ImpalaTestSuite):
     try:
       fn()
       assert False, "Expected invalid handle"
-    except ImpalaBeeswaxException, e:
+    except ImpalaBeeswaxException as e:
       assert "Query id" in str(e) and "not found" in str(e), str(e)
 
   def _assert_profile_access_denied(self, fn):
@@ -94,5 +94,5 @@ class TestBeeswax(ImpalaTestSuite):
     try:
       fn()
       assert False, "Expected invalid handle"
-    except ImpalaBeeswaxException, e:
+    except ImpalaBeeswaxException as e:
       assert "is not authorized to access the runtime profile" in str(e), str(e)
diff --git a/tests/query_test/test_decimal_queries.py b/tests/query_test/test_decimal_queries.py
index 13c64e341..a361eef59 100644
--- a/tests/query_test/test_decimal_queries.py
+++ b/tests/query_test/test_decimal_queries.py
@@ -172,7 +172,7 @@ class TestDecimalOverflowExprs(ImpalaTestSuite):
       try:
         self.execute_query_using_client(self.client, query_1, vector)
         assert False, "Query was expected to fail"
-      except ImpalaBeeswaxException, e:
+      except ImpalaBeeswaxException as e:
         assert "Decimal expression overflowed" in str(e)
 
       result = self.execute_query_expect_success(self.client,
@@ -187,7 +187,7 @@ class TestDecimalOverflowExprs(ImpalaTestSuite):
     try:
       self.execute_query_using_client(self.client, query_1, vector)
       assert False, "Query was expected to fail"
-    except ImpalaBeeswaxException, e:
+    except ImpalaBeeswaxException as e:
       assert "Decimal expression overflowed" in str(e)
 
     result = self.execute_query_expect_success(self.client,
@@ -215,7 +215,7 @@ class TestDecimalOverflowExprs(ImpalaTestSuite):
     try:
       self.execute_query_using_client(self.client, query_2, vector)
       assert False, "Query was expected to fail"
-    except ImpalaBeeswaxException, e:
+    except ImpalaBeeswaxException as e:
       assert "Decimal expression overflowed" in str(e)
 
     result = self.execute_query_expect_success(self.client,
diff --git a/tests/query_test/test_insert.py b/tests/query_test/test_insert.py
index 213be78b7..05a40401f 100644
--- a/tests/query_test/test_insert.py
+++ b/tests/query_test/test_insert.py
@@ -124,7 +124,7 @@ class TestInsertQueries(ImpalaTestSuite):
     try:
       self.client.execute("select s from {0}".format(table_name))
       assert False, "Expected query to fail"
-    except Exception, e:
+    except Exception as e:
       assert "Memory limit exceeded" in str(e)
 
 
diff --git a/tests/query_test/test_nested_types.py b/tests/query_test/test_nested_types.py
index 8c1c50e9f..999989440 100644
--- a/tests/query_test/test_nested_types.py
+++ b/tests/query_test/test_nested_types.py
@@ -619,12 +619,12 @@ class TestParquetArrayEncodings(ImpalaTestSuite):
       expected_err = "has an incompatible Parquet schema"
       try:
         self.execute_query("select item from %s.col1.item" % full_name, qopts)
-      except Exception, e:
+      except Exception as e:
         assert expected_err in str(e)
       try:
         self.execute_query("select cnt from %s t, (select count(*) cnt from t.col1) v"\
           % full_name, qopts)
-      except Exception, e:
+      except Exception as e:
         assert expected_err in str(e)
 
   # $ parquet-tools schema UnannotatedListOfPrimitives.parquet
@@ -851,7 +851,7 @@ class TestMaxNestingDepth(ImpalaTestSuite):
     try:
       self.client.execute("explain select 1 from %s.above_max_depth" % unique_database)
       assert False, "Expected table loading to fail."
-    except ImpalaBeeswaxException, e:
+    except ImpalaBeeswaxException as e:
       assert "Type exceeds the maximum nesting depth" in str(e)
 
 
diff --git a/tests/query_test/test_partitioning.py b/tests/query_test/test_partitioning.py
index acabdcbbc..649d785fc 100644
--- a/tests/query_test/test_partitioning.py
+++ b/tests/query_test/test_partitioning.py
@@ -85,7 +85,7 @@ class TestPartitioning(ImpalaTestSuite):
     # INSERT into a boolean column is disabled in Impala due to this Hive bug.
     try:
       self.execute_query("insert into %s partition(bool_col=true) select 1" % full_name)
-    except ImpalaBeeswaxException, e:
+    except ImpalaBeeswaxException as e:
       assert 'AnalysisException: INSERT into table with BOOLEAN partition column (%s) '\
           'is not supported: %s' % ('b', full_name) in str(e)
 
diff --git a/tests/query_test/test_query_mem_limit.py b/tests/query_test/test_query_mem_limit.py
index 2586d39bc..209fca84f 100644
--- a/tests/query_test/test_query_mem_limit.py
+++ b/tests/query_test/test_query_mem_limit.py
@@ -112,7 +112,7 @@ class TestQueryMemLimit(ImpalaTestSuite):
     try:
       self.execute_query(query, exec_options, table_format=table_format)
       assert should_succeed, "Query was expected to fail"
-    except ImpalaBeeswaxException, e:
+    except ImpalaBeeswaxException as e:
       assert not should_succeed, "Query should not have failed: %s" % e
 
 
diff --git a/tests/query_test/test_udfs.py b/tests/query_test/test_udfs.py
index 035d01fe4..d70a50663 100644
--- a/tests/query_test/test_udfs.py
+++ b/tests/query_test/test_udfs.py
@@ -375,13 +375,13 @@ class TestUdfExecution(TestUdfBase):
     try:
       self.run_test_case('QueryTest/udf-mem-limit', vector, use_db=unique_database)
       assert False, "Query was expected to fail"
-    except ImpalaBeeswaxException, e:
+    except ImpalaBeeswaxException as e:
       self._check_mem_limit_exception(e)
 
     try:
       self.run_test_case('QueryTest/uda-mem-limit', vector, use_db=unique_database)
       assert False, "Query was expected to fail"
-    except ImpalaBeeswaxException, e:
+    except ImpalaBeeswaxException as e:
       self._check_mem_limit_exception(e)
 
     # It takes a long time for Impala to free up memory after this test, especially if
@@ -513,7 +513,7 @@ class TestUdfTargeted(TestUdfBase):
       self.execute_query_using_client(
           client, "select `{0}`.`pi_missing_jar`()".format(unique_database), vector)
       assert False, "Query expected to fail"
-    except ImpalaBeeswaxException, e:
+    except ImpalaBeeswaxException as e:
       assert "Failed to get file info" in str(e)
 
   def test_libs_with_same_filenames(self, vector, unique_database):
diff --git a/tests/shell/test_shell_commandline.py b/tests/shell/test_shell_commandline.py
index d097ccdaf..484f7b97a 100644
--- a/tests/shell/test_shell_commandline.py
+++ b/tests/shell/test_shell_commandline.py
@@ -740,7 +740,7 @@ class TestImpalaShell(ImpalaTestSuite):
       query_file_handle = open(query_file, 'r')
       query = query_file_handle.read()
       query_file_handle.close()
-    except Exception, e:
+    except Exception as e:
       assert query_file_handle is not None, "Exception %s: Could not find query file" % e
     result = run_impala_shell_cmd(vector, args, expect_success=True, stdin_input=query)
     output = result.stdout
@@ -942,7 +942,7 @@ class TestImpalaShell(ImpalaTestSuite):
           try:
             connection, client_address = sock.accept()
             break
-          except IOError, e:
+          except IOError as e:
             if e.errno != errno.EINTR:
               raise
         data = connection.recv(1024)
diff --git a/tests/statestore/test_statestore.py b/tests/statestore/test_statestore.py
index b69b3f2f8..9daedba30 100644
--- a/tests/statestore/test_statestore.py
+++ b/tests/statestore/test_statestore.py
@@ -119,7 +119,7 @@ class KillableThreadedServer(TServer):
       try:
         cnxn.open()
         return
-      except Exception, e:
+      except Exception as e:
         if i == num_tries - 1: raise
       time.sleep(0.1)
 
@@ -129,7 +129,7 @@ class KillableThreadedServer(TServer):
       try:
         cnxn.open()
         time.sleep(0.1)
-      except Exception, e:
+      except Exception as e:
         return
     raise Exception("Server did not stop")
 
@@ -152,9 +152,9 @@ class KillableThreadedServer(TServer):
     try:
       while not self.is_shutdown:
         self.processor.process(iprot, oprot)
-    except TTransport.TTransportException, tx:
+    except TTransport.TTransportException as tx:
       pass
-    except Exception, x:
+    except Exception as x:
       print x
 
     itrans.close()
@@ -203,7 +203,7 @@ class StatestoreSubscriber(object):
       if self.heartbeat_cb is not None and self.exception is None:
         try:
           response = self.heartbeat_cb(self, args)
-        except Exception, e:
+        except Exception as e:
           self.exception = e
       self.heartbeat_event.notify()
     finally:
@@ -219,7 +219,7 @@ class StatestoreSubscriber(object):
       if self.update_cb is not None and self.exception is None:
         try:
           response = self.update_cb(self, args)
-        except Exception, e:
+        except Exception as e:
           # Print the original backtrace so it doesn't get lost.
           traceback.print_exc()
           self.exception = e
diff --git a/tests/unittests/test_result_verifier.py b/tests/unittests/test_result_verifier.py
index e6bf9ba64..94d2fd917 100644
--- a/tests/unittests/test_result_verifier.py
+++ b/tests/unittests/test_result_verifier.py
@@ -48,13 +48,13 @@ class TestResultVerifier(ImpalaTestSuite):
     try:
       res.rows[0]['does_not_exist']
       assert False, 'Expected error due to column alias not existing'
-    except IndexError, e:
+    except IndexError as e:
       assert "No column with label: does_not_exist" in e.message
 
     try:
       res.rows[0][2]
       assert False, 'Expected error due to column position not existing'
-    except IndexError, e:
+    except IndexError as e:
       assert 'list index out of range' in e.message
 
   def test_compute_aggregation(self, vector):