Member since
03-01-2017
1
Post
0
Kudos Received
0
Solutions
03-01-2017
09:09 AM
import os
import subprocess
class BeeLine(object):
"""Make empoyee person class with names, and title required."""
def __init__(self, principal, database, server='localhost', port=10000):
self.principal = principal
self.database = database
self.server = server
self.port = port
if not isinstance(port, (int, long)):
raise TypeError("Error, port must be an integer")
url=("'jdbc:hive2://" + server + ":" + str(port) + "/default;principal="
+ principal + "'")
self.options=[ "beeline"
, "-u"
, url
, "--fastConnect=true"
, "--showHeader=false"
, "--verbose=false"
, "--showWarnings=false"
, "--silent=true"
]
def show_tables(self):
"""Show tables of object's database"""
cmd=[]
cmd.extend(self.options)
cmd.append("--outputFormat=csv2")
cmd.append("-e")
cmd.append("use {0};".format(self.database))
cmd.append("-e")
cmd.append("show tables;")
return self._run_cmd(cmd)
def _run_cmd(self, cmd):
"""Private function. Run command, from array, and return stdout"""
print cmd
stdout = subprocess.check_call(cmd) <<<< Command run HERE
return stdout
#
# Main
#
beeline=BeeLine(
principal='hive/dev15-namenode-01.example.com@example.COM'
, database='tsz')
tables=beeline.show_tables()
print tables This is what made your code work for me
... View more