You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by ta...@apache.org on 2019/03/23 23:39:45 UTC

[impala] 03/03: IMPALA-8337: Fix OrderedDict Python compatibility issue in Impala shell

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

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

commit eb95c912cb7e720caf66388942b4e94d95e95658
Author: Fredy Wijaya <fw...@cloudera.com>
AuthorDate: Thu Mar 21 16:42:09 2019 -0700

    IMPALA-8337: Fix OrderedDict Python compatibility issue in Impala shell
    
    IMPALA-8317 added a patch that uses OrderedDict, which is not available
    on Python 2.6 or lower. The patch in IMPALA-8317 also requires a newer
    version of configparser to handle duplicate keys, which is not available
    in Python 2.6. This patch fixes the issue by using the OrderedDict from
    ordereddict third-party library when running on Python 2.6 or lower and
    using configparser from the backport.
    
    Testing:
    - Ran all E2E shell tests on Python 2.6 and 2.7
    
    Change-Id: Iab1a33542319e9bb75d806bfd38b158995b54aa9
    Reviewed-on: http://gerrit.cloudera.org:8080/12830
    Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
 infra/python/deps/requirements.txt |  2 ++
 shell/option_parser.py             | 12 ++++++++----
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/infra/python/deps/requirements.txt b/infra/python/deps/requirements.txt
index fd07ca8..eb0be83 100644
--- a/infra/python/deps/requirements.txt
+++ b/infra/python/deps/requirements.txt
@@ -66,3 +66,5 @@ ipython == 1.2.1
   apipkg == 1.4
 
 virtualenv == 13.1.0
+# This is a backport of Python'3 configparser that supports Python 2.6+.
+configparser == 3.7.3
diff --git a/shell/option_parser.py b/shell/option_parser.py
index 2296596..28b4870 100755
--- a/shell/option_parser.py
+++ b/shell/option_parser.py
@@ -27,11 +27,15 @@
 # EXPLAIN_LEVEL=2
 # MT_DOP=2
 
-import ConfigParser
+import configparser
 import sys
 from impala_shell_config_defaults import impala_shell_defaults
 from optparse import OptionParser
-from collections import OrderedDict
+try:
+  from collections import OrderedDict
+except ImportError:
+  # Python 2.6 and below does not have OrderedDict.
+  from ordereddict import OrderedDict
 
 
 class ConfigFileFormatError(Exception):
@@ -115,7 +119,7 @@ def get_config_from_file(config_filename, option_list):
   """
   # Customize the ConfigParser to allow duplicate keys. Values from duplicate keys will
   # be appended with new lines.
-  config = ConfigParser.RawConfigParser(dict_type=MultiOrderedDict)
+  config = configparser.RawConfigParser(dict_type=MultiOrderedDict, strict=False)
   try:
     config.read(config_filename)
   except Exception, e:
@@ -132,7 +136,7 @@ def get_config_from_file(config_filename, option_list):
 
   # For query options, we use a standard config parser since we don't want to allow
   # duplicate options.
-  config = ConfigParser.ConfigParser()
+  config = configparser.ConfigParser(strict=False)
   try:
     config.read(config_filename)
   except Exception, e: