mirror of
https://github.com/apache/impala.git
synced 2025-12-25 02:03:09 -05:00
IMPALA-11977: Fix Python 3 broken imports and object model differences
Python 3 changed some object model methods: - __nonzero__ was removed in favor of __bool__ - func_dict / func_name were removed in favor of __dict__ / __name__ - The next() function was deprecated in favor of __next__ (Code locations should use next(iter) rather than iter.next()) - metaclasses are specified a different way - Locations that specify __eq__ should also specify __hash__ Python 3 also moved some packages around (urllib2, Queue, httplib, etc), and this adapts the code to use the new locations (usually handled on Python 2 via future). This also fixes the code to avoid referencing exception variables outside the exception block and variables outside of a comprehension. Several of these seem like false positives, but it is better to avoid the warning. This fixes these pylint warnings: bad-python3-import eq-without-hash metaclass-assignment next-method-called nonzero-method exception-escape comprehension-escape Testing: - Ran core tests - Ran release exhaustive tests Change-Id: I988ae6c139142678b0d40f1f4170b892eabf25ee Reviewed-on: http://gerrit.cloudera.org:8080/19592 Reviewed-by: Joe McDonnell <joemcdonnell@cloudera.com> Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
from builtins import int, range, zip
|
||||
from future.utils import with_metaclass
|
||||
import hdfs
|
||||
import logging
|
||||
import os
|
||||
@@ -34,17 +35,20 @@ from collections import defaultdict
|
||||
from collections import OrderedDict
|
||||
from contextlib import contextmanager
|
||||
from getpass import getuser
|
||||
from io import BytesIO
|
||||
from multiprocessing.pool import ThreadPool
|
||||
from random import choice
|
||||
from StringIO import StringIO
|
||||
from sys import maxsize
|
||||
from tempfile import mkdtemp
|
||||
from threading import Lock
|
||||
from time import mktime, strptime
|
||||
from urlparse import urlparse
|
||||
from xml.etree.ElementTree import parse as parse_xml
|
||||
from zipfile import ZipFile
|
||||
|
||||
try:
|
||||
from urllib.parse import urlparse
|
||||
except ImportError:
|
||||
from urlparse import urlparse
|
||||
|
||||
from tests.comparison.db_connection import HiveConnection, ImpalaConnection
|
||||
from tests.common.environ import HIVE_MAJOR_VERSION
|
||||
@@ -65,14 +69,12 @@ CM_CLEAR_PORT = 7180
|
||||
CM_TLS_PORT = 7183
|
||||
|
||||
|
||||
class Cluster(object):
|
||||
class Cluster(with_metaclass(ABCMeta, object)):
|
||||
"""This is a base class for clusters. Cluster classes provide various methods for
|
||||
interacting with a cluster. Ideally the various cluster implementations provide
|
||||
the same set of methods so any cluster implementation can be chosen at runtime.
|
||||
"""
|
||||
|
||||
__metaclass__ = ABCMeta
|
||||
|
||||
def __init__(self):
|
||||
self._hadoop_configs = None
|
||||
self._local_hadoop_conf_dir = None
|
||||
@@ -323,7 +325,7 @@ class CmCluster(Cluster):
|
||||
|
||||
def _init_local_hadoop_conf_dir(self):
|
||||
self._local_hadoop_conf_dir = mkdtemp()
|
||||
data = StringIO(self.cm.get("/clusters/%s/services/%s/clientConfig"
|
||||
data = BytesIO(self.cm.get("/clusters/%s/services/%s/clientConfig"
|
||||
% (self.cm_cluster.name, self._find_service("HIVE").name)))
|
||||
zip_file = ZipFile(data)
|
||||
for name in zip_file.namelist():
|
||||
@@ -655,9 +657,7 @@ class CmImpala(Impala):
|
||||
raise Exception("Failed to restart Impala: %s" % command.resultMessage)
|
||||
|
||||
|
||||
class Impalad(object):
|
||||
|
||||
__metaclass__ = ABCMeta
|
||||
class Impalad(with_metaclass(ABCMeta, object)):
|
||||
|
||||
def __init__(self):
|
||||
self.impala = None
|
||||
|
||||
Reference in New Issue
Block a user