You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by he...@apache.org on 2017/05/17 16:17:00 UTC

[2/5] incubator-impala git commit: IMPALA-5127: Add history_max option

IMPALA-5127: Add history_max option

Allow users to keep a longer history of queries if desired.  I
personally find it useful to keep a long history of queries to
reference and want to bump this up to a very large value, but
keep the default reasonable.  Also change the config loader
to not freak out over unknown parameters so as not to break
for users that end up with new options set running on older
shells.

Testing: Created .impalarc as follows, now getting more history saved.
Put broken things in .impalarc and make sure they are logged as
warnings.

[impala]
history_max=1000

Change-Id: Iaf65bbecb8fd7f1105aac62b6745d6125a603d7f
Reviewed-on: http://gerrit.cloudera.org:8080/6335
Reviewed-by: Michael Brown <mi...@cloudera.com>
Tested-by: Impala Public Jenkins


Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/5905083b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/5905083b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/5905083b

Branch: refs/heads/master
Commit: 5905083bfec82dd179fe94c1a109445f69d1faea
Parents: c826af6
Author: Zach Amsden <za...@cloudera.com>
Authored: Thu Mar 9 22:24:16 2017 +0000
Committer: Impala Public Jenkins <im...@gerrit.cloudera.org>
Committed: Tue May 16 02:35:22 2017 +0000

----------------------------------------------------------------------
 docs/topics/impala_shell_options.xml  | 17 +++++++++++++++
 shell/impala_shell.py                 |  8 ++++++--
 shell/impala_shell_config_defaults.py | 33 +++++++++++++++---------------
 shell/option_parser.py                |  6 ++++++
 4 files changed, 46 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/5905083b/docs/topics/impala_shell_options.xml
----------------------------------------------------------------------
diff --git a/docs/topics/impala_shell_options.xml b/docs/topics/impala_shell_options.xml
index b2ce883..6e370fe 100644
--- a/docs/topics/impala_shell_options.xml
+++ b/docs/topics/impala_shell_options.xml
@@ -198,6 +198,23 @@ under the License.
             <row>
               <entry>
                 <p>
+                  N/A
+                </p>
+              </entry>
+              <entry rev="2.9.0 IMPALA-5127">
+                <p>
+                  history_max=1000
+                </p>
+              </entry>
+              <entry>
+                <p>
+                  Sets the maximum number of queries to store in the history file.
+                </p>
+              </entry>
+            </row>
+            <row>
+              <entry>
+                <p>
                   -i <varname>hostname</varname> or
                   --impalad=<varname>hostname</varname>[:<varname>portnum</varname>]
                 </p>

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/5905083b/shell/impala_shell.py
----------------------------------------------------------------------
diff --git a/shell/impala_shell.py b/shell/impala_shell.py
index 630a4e1..8af2b57 100755
--- a/shell/impala_shell.py
+++ b/shell/impala_shell.py
@@ -46,7 +46,6 @@ from thrift.Thrift import TException
 
 VERSION_FORMAT = "Impala Shell v%(version)s (%(git_hash)s) built on %(build_date)s"
 VERSION_STRING = "build version not available"
-HISTORY_LENGTH = 100
 
 # Tarball / packaging build makes impala_build_version available
 try:
@@ -181,7 +180,12 @@ class ImpalaShell(cmd.Cmd):
       self.interactive = True
       try:
         self.readline = __import__('readline')
-        self.readline.set_history_length(HISTORY_LENGTH)
+        try:
+          self.readline.set_history_length(int(options.history_max))
+        except ValueError:
+          print_to_stderr("WARNING: history_max option malformed %s\n"
+            % options.history_max)
+          self.readline.set_history_length(1000)
       except ImportError:
         self._disable_readline()
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/5905083b/shell/impala_shell_config_defaults.py
----------------------------------------------------------------------
diff --git a/shell/impala_shell_config_defaults.py b/shell/impala_shell_config_defaults.py
index 4ae02dd..c50ad87 100644
--- a/shell/impala_shell_config_defaults.py
+++ b/shell/impala_shell_config_defaults.py
@@ -24,26 +24,27 @@ import os
 import socket
 
 impala_shell_defaults = {
+            'ca_cert': None,
+            'config_file': os.path.expanduser("~/.impalarc"),
+            'default_db': None,
+            'history_max': 1000,
+            'ignore_query_failure': False,
             'impalad': socket.getfqdn() + ':21000',
-            'query': None,
-            'query_file': None,
-            'use_kerberos': False,
+            'kerberos_service_name': 'impala',
+            'output_delimiter': '\\t',
             'output_file': None,
-            'write_delimited': False,
             'print_header': False,
-            'output_delimiter': '\\t',
-            'kerberos_service_name': 'impala',
-            'verbose': True,
-            'show_profiles': False,
-            'version': False,
-            'ignore_query_failure': False,
+            'print_progress' : False,
+            'print_summary' : False,
+            'query': None,
+            'query_file': None,
             'refresh_after_connect': False,
-            'default_db': None,
+            'show_profiles': False,
+            'ssl': False,
+            'use_kerberos': False,
             'use_ldap': False,
             'user': getpass.getuser(),
-            'ssl': False,
-            'ca_cert': None,
-            'config_file': os.path.expanduser("~/.impalarc"),
-            'print_progress' : False,
-            'print_summary' : False
+            'verbose': True,
+            'version': False,
+            'write_delimited': False,
             }

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/5905083b/shell/option_parser.py
----------------------------------------------------------------------
diff --git a/shell/option_parser.py b/shell/option_parser.py
index c455f57..0a30ed4 100755
--- a/shell/option_parser.py
+++ b/shell/option_parser.py
@@ -26,6 +26,7 @@
 #
 
 import ConfigParser
+import sys
 from impala_shell_config_defaults import impala_shell_defaults
 from optparse import OptionParser
 
@@ -44,6 +45,11 @@ def get_config_from_file(config_filename):
     loaded_options = config.items(section_title);
 
     for i, (option, value) in enumerate(loaded_options):
+      if option not in impala_shell_defaults:
+        print >> sys.stderr, "WARNING: Unable to read configuration file correctly. " \
+          "Check formatting: '%s'\n" % option;
+        continue
+
       if impala_shell_defaults[option] in [True, False]:
         # validate the option if it can only be a boolean value
         # the only choice for these options is true or false