phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maryann...@apache.org
Subject [43/50] [abbrv] phoenix git commit: PHOENIX-3517 Switch sqlline-thin.py to use argparse
Date Tue, 27 Dec 2016 18:30:06 GMT
PHOENIX-3517 Switch sqlline-thin.py to use argparse


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/8c636a42
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/8c636a42
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/8c636a42

Branch: refs/heads/calcite
Commit: 8c636a42149f3b3783edda87be6db4ee99df96ec
Parents: 006bedd
Author: Josh Elser <elserj@apache.org>
Authored: Sat Dec 3 17:33:46 2016 -0500
Committer: Josh Elser <elserj@apache.org>
Committed: Sun Dec 18 00:12:04 2016 -0500

----------------------------------------------------------------------
 bin/sqlline-thin.py | 49 +++++++++++++++++++++++++++++-------------------
 1 file changed, 30 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/8c636a42/bin/sqlline-thin.py
----------------------------------------------------------------------
diff --git a/bin/sqlline-thin.py b/bin/sqlline-thin.py
index 12501dc..e4cb540 100755
--- a/bin/sqlline-thin.py
+++ b/bin/sqlline-thin.py
@@ -25,6 +25,7 @@ import sys
 import phoenix_utils
 import atexit
 import urlparse
+import argparse
 
 global childProc
 childProc = None
@@ -36,10 +37,25 @@ def kill_child():
             os.system("reset")
 atexit.register(kill_child)
 
+parser = argparse.ArgumentParser(description='Launches the Apache Phoenix Thin Client.')
+# Positional argument "url" is optional
+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')
+parser.add_argument('-a', '--authentication', help='Mechanism for HTTP authentication.',
choices=('SPNEGO', 'BASIC', 'DIGEST', 'NONE'), default='')
+parser.add_argument('-s', '--serialization', help='Serialization type for HTTP API.', choices=('PROTOBUF',
'JSON'), default=None)
+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')
+args=parser.parse_args()
+
 phoenix_utils.setPath()
 
-url = "localhost:8765"
-sqlfile = ""
+url = args.url
+sqlfile = args.sqlfile
 serialization_key = 'phoenix.queryserver.serialization'
 
 def usage_and_exit():
@@ -86,25 +102,12 @@ def get_serialization():
         return default_serialization
     return stdout
 
-if len(sys.argv) == 1:
-    pass
-elif len(sys.argv) == 2:
-    if os.path.isfile(sys.argv[1]):
-        sqlfile = sys.argv[1]
-    else:
-        url = sys.argv[1]
-elif len(sys.argv) == 3:
-    url = sys.argv[1]
-    sqlfile = sys.argv[2]
-else:
-    usage_and_exit()
-
 url = cleanup_url(url)
 
 if sqlfile != "":
     sqlfile = "--run=" + sqlfile
 
-colorSetting = "true"
+colorSetting = args.color
 # disable color setting for windows OS
 if os.name == 'nt':
     colorSetting = "false"
@@ -113,7 +116,7 @@ if os.name == 'nt':
 # HBase/Phoenix client side property override
 hbase_config_path = os.getenv('HBASE_CONF_DIR', phoenix_utils.current_dir)
 
-serialization = get_serialization()
+serialization = args.serialization if args.serialization else get_serialization()
 
 java_home = os.getenv('JAVA_HOME')
 
@@ -145,13 +148,21 @@ if java_home:
 else:
     java = 'java'
 
+jdbc_url = 'jdbc:phoenix:thin:url=' + url + ';serialization=' + serialization
+if args.authentication:
+    jdbc_url += ';authentication=' + args.authentication
+if args.auth_user:
+    jdbc_url += ';avatica_user=' + args.auth_user
+if args.auth_password:
+    jdbc_url += ';avatica_password=' + args.auth_password
+
 java_cmd = java + ' $PHOENIX_OPTS ' + \
     ' -cp "' + phoenix_utils.hbase_conf_dir + os.pathsep + phoenix_utils.phoenix_thin_client_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") + \
     " org.apache.phoenix.queryserver.client.SqllineWrapper -d org.apache.phoenix.queryserver.client.Driver
" + \
-    " -u \"jdbc:phoenix:thin:url=" + url + ";serialization=" + serialization + "\"" + \
-    " -n none -p none --color=" + colorSetting + " --fastConnect=false --verbose=true " +
\
+    ' -u "' + jdbc_url + '"' + " -n " + args.user + " -p " + args.password + \
+    " --color=" + colorSetting + " --fastConnect=false --verbose=" + args.verbose + \
     " --incremental=false --isolation=TRANSACTION_READ_COMMITTED " + sqlfile
 
 exitcode = subprocess.call(java_cmd, shell=True)


Mime
View raw message