PHOENIX-3567 Use argparse for sqlline
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/4f97085e Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/4f97085e Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/4f97085e Branch: refs/heads/encodecolumns2 Commit: 4f97085ee4f206589d0ce160c55d9ed0187ec989 Parents: 3d1abf5 Author: Josh Elser <els...@apache.org> Authored: Thu Jan 5 12:34:48 2017 -0500 Committer: Josh Elser <els...@apache.org> Committed: Mon Jan 16 16:18:36 2017 -0500 ---------------------------------------------------------------------- bin/phoenix_utils.py | 5 +++++ bin/sqlline-thin.py | 17 ++++++++-------- bin/sqlline.py | 52 ++++++++++++++++++++--------------------------- 3 files changed, 35 insertions(+), 39 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/4f97085e/bin/phoenix_utils.py ---------------------------------------------------------------------- diff --git a/bin/phoenix_utils.py b/bin/phoenix_utils.py index 2da094f..580a78b 100755 --- a/bin/phoenix_utils.py +++ b/bin/phoenix_utils.py @@ -198,6 +198,11 @@ def shell_quote(args): import pipes return " ".join([pipes.quote(v) for v in args]) +def common_sqlline_args(parser): + parser.add_argument('-v', '--verbose', help='Verbosity on sqlline.', default='true') + parser.add_argument('-c', '--color', help='Color setting for sqlline.', default='true') + parser.add_argument('-fc', '--fastconnect', help='Fetch all schemas on initial connection', default='false') + if __name__ == "__main__": setPath() print "phoenix_class_path:", phoenix_class_path http://git-wip-us.apache.org/repos/asf/phoenix/blob/4f97085e/bin/sqlline-thin.py ---------------------------------------------------------------------- diff --git a/bin/sqlline-thin.py b/bin/sqlline-thin.py index e4cb540..47384d8 100755 --- a/bin/sqlline-thin.py +++ b/bin/sqlline-thin.py @@ -42,14 +42,16 @@ parser = argparse.ArgumentParser(description='Launches the Apache Phoenix Thin C parser.add_argument('url', nargs='?', help='The URL to the Phoenix Query Server.', default='http://localhost:8765') # Positional argument "sqlfile" is optional parser.add_argument('sqlfile', nargs='?', help='A file of SQL commands to execute.', default='') -parser.add_argument('-u', '--user', help='Username for database authentication (unsupported).', default='none') -parser.add_argument('-p', '--password', help='Password for database authentication (unsupported).', default='none') +# Avatica wire authentication parser.add_argument('-a', '--authentication', help='Mechanism for HTTP authentication.', choices=('SPNEGO', 'BASIC', 'DIGEST', 'NONE'), default='') +# Avatica wire serialization parser.add_argument('-s', '--serialization', help='Serialization type for HTTP API.', choices=('PROTOBUF', 'JSON'), default=None) +# Avatica authentication parser.add_argument('-au', '--auth-user', help='Username for HTTP authentication.') parser.add_argument('-ap', '--auth-password', help='Password for HTTP authentication.') -parser.add_argument('-v', '--verbose', help='Verbosity on sqlline.', default='true') -parser.add_argument('-c', '--color', help='Color setting for sqlline.', default='true') +# Common arguments across sqlline.py and sqlline-thin.py +phoenix_utils.common_sqlline_args(parser) +# Parse the args args=parser.parse_args() phoenix_utils.setPath() @@ -58,9 +60,6 @@ url = args.url sqlfile = args.sqlfile serialization_key = 'phoenix.queryserver.serialization' -def usage_and_exit(): - sys.exit("usage: sqlline-thin.py [host[:port]] [sql_file]") - def cleanup_url(url): parsed = urlparse.urlparse(url) if parsed.scheme == "": @@ -161,8 +160,8 @@ java_cmd = java + ' $PHOENIX_OPTS ' + \ os.pathsep + phoenix_utils.hadoop_conf + os.pathsep + phoenix_utils.hadoop_classpath + '" -Dlog4j.configuration=file:' + \ os.path.join(phoenix_utils.current_dir, "log4j.properties") + \ " org.apache.phoenix.queryserver.client.SqllineWrapper -d org.apache.phoenix.queryserver.client.Driver " + \ - ' -u "' + jdbc_url + '"' + " -n " + args.user + " -p " + args.password + \ - " --color=" + colorSetting + " --fastConnect=false --verbose=" + args.verbose + \ + ' -u "' + jdbc_url + '"' + " -n none -p none " + \ + " --color=" + colorSetting + " --fastConnect=" + args.fastconnect + " --verbose=" + args.verbose + \ " --incremental=false --isolation=TRANSACTION_READ_COMMITTED " + sqlfile exitcode = subprocess.call(java_cmd, shell=True) http://git-wip-us.apache.org/repos/asf/phoenix/blob/4f97085e/bin/sqlline.py ---------------------------------------------------------------------- diff --git a/bin/sqlline.py b/bin/sqlline.py index 474968f..7a724de 100755 --- a/bin/sqlline.py +++ b/bin/sqlline.py @@ -24,6 +24,7 @@ import subprocess import sys import phoenix_utils import atexit +import argparse global childProc childProc = None @@ -37,36 +38,26 @@ atexit.register(kill_child) phoenix_utils.setPath() -def printUsage(): - print "\nUsage: sqlline.py [zookeeper] \ -[optional_sql_file] \nExample: \n 1. sqlline.py \n \ -2. sqlline.py localhost:2181:/hbase \n 3. sqlline.py \ -localhost:2181:/hbase ../examples/stock_symbol.sql \n \ -4. sqlline.py ../examples/stock_symbol.sql" - sys.exit(-1) - -if len(sys.argv) > 3: - printUsage() +parser = argparse.ArgumentParser(description='Launches the Apache Phoenix Client.') +# Positional argument 'zookeepers' is optional +parser.add_argument('zookeepers', nargs='?', help='The ZooKeeper quorum string', default='localhost:2181:/hbase') +# Positional argument 'sqlfile' is optional +parser.add_argument('sqlfile', nargs='?', help='A file of SQL commands to execute', default='') +# Common arguments across sqlline.py and sqlline-thin.py +phoenix_utils.common_sqlline_args(parser) +# Parse the args +args=parser.parse_args() -sqlfile = "" -zookeeper = "" +zookeeper = args.zookeepers +sqlfile = args.sqlfile # HBase configuration folder path (where hbase-site.xml reside) for # HBase/Phoenix client side property override hbase_config_path = os.getenv('HBASE_CONF_DIR', phoenix_utils.current_dir) -if len(sys.argv) == 2: - if os.path.isfile(sys.argv[1]): - sqlfile = sys.argv[1] - else: - zookeeper = sys.argv[1] - -if len(sys.argv) == 3: - if os.path.isfile(sys.argv[1]): - printUsage() - else: - zookeeper = sys.argv[1] - sqlfile = sys.argv[2] +if sqlfile and not os.path.isfile(sqlfile): + parser.print_help() + sys.exit(-1) if sqlfile: sqlfile = "--run=" + phoenix_utils.shell_quote([sqlfile]) @@ -101,19 +92,20 @@ if java_home: else: java = 'java' -colorSetting = "true" +colorSetting = args.color # disable color setting for windows OS if os.name == 'nt': colorSetting = "false" java_cmd = java + ' $PHOENIX_OPTS ' + \ - ' -cp "' + hbase_config_path + os.pathsep + phoenix_utils.hbase_conf_dir + os.pathsep + phoenix_utils.phoenix_client_jar + os.pathsep + phoenix_utils.hadoop_common_jar + os.pathsep + phoenix_utils.hadoop_hdfs_jar + \ + ' -cp "' + hbase_config_path + os.pathsep + phoenix_utils.hbase_conf_dir + os.pathsep + phoenix_utils.phoenix_client_jar + \ + os.pathsep + phoenix_utils.hadoop_common_jar + os.pathsep + phoenix_utils.hadoop_hdfs_jar + \ os.pathsep + phoenix_utils.hadoop_conf + os.pathsep + phoenix_utils.hadoop_classpath + '" -Dlog4j.configuration=file:' + \ os.path.join(phoenix_utils.current_dir, "log4j.properties") + \ - " sqlline.SqlLine -d org.apache.phoenix.jdbc.PhoenixDriver \ --u jdbc:phoenix:" + phoenix_utils.shell_quote([zookeeper]) + \ - " -n none -p none --color=" + colorSetting + " --fastConnect=false --verbose=true \ ---incremental=false --isolation=TRANSACTION_READ_COMMITTED " + sqlfile + " sqlline.SqlLine -d org.apache.phoenix.jdbc.PhoenixDriver" + \ + " -u jdbc:phoenix:" + phoenix_utils.shell_quote([zookeeper]) + \ + " -n none -p none --color=" + colorSetting + " --fastConnect=" + args.fastconnect + \ + " --verbose=" + args.verbose + " --incremental=false --isolation=TRANSACTION_READ_COMMITTED " + sqlfile childProc = subprocess.Popen(java_cmd, shell=True) #Wait for child process exit