Created 02-08-2017 07:00 PM
I'm creating some python code to execute some beeline commands. The command looks ok, but I get an error:
WARNING: Use "yarn jar" to launch YARN applications.
Error: Error while compiling statement: FAILED: ParseException line 1:8
character '<EOF>' not supported here (state=42000,code=40000)
Error: Error while compiling statement: FAILED: ParseException line 1:12
character '<EOF>' not supported here (state=42000,code=40000)
['beeline', "-u 'jdbc:hive2://localhost:10000/default;principal=hive/dev15-namenode-01.example.com@example.COM'", '--fastConnect=true', '--showHeader=false', '--verbose=false', '--showWarnings=false', '--silent=true', '--outputFormat=csv2', "-e 'use tsz;'", "-e 'show tables;'"]
Traceback (most recent call last):
File "./beeline.py", line 55, in <module>
tables=beeline.show_tables()
File "./beeline.py", line 43, in show_tables
return self._run_cmd(cmd)
File "./beeline.py", line 48, in _run_cmd
stdout = subprocess.check_call(cmd)
File "/usr/lib64/python2.6/subprocess.py", line 505, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['beeline', "-u 'jdbc:hive2://localhost:10000/default;principal=hive/dev15-namenode-01.example.com@example.COM'", '--fastConnect=true', '--showHeader=false', '--verbose=false', '--showWarnings=false', '--silent=true', '--outputFormat=csv2', "-e 'use tsz;'", "-e 'show tables;'"]' returned non-zero exit status 2
The errors seem to correspond to the semicolons in the -e blocks. I know the command via the shell works. Any ideas on the cause?
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 'use " + self.database + ";'")
cmd.append("-e '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
Created 02-08-2017 08:04 PM
There already exists a python client for hiveserver2, please use this recommended client.
Created 02-08-2017 08:20 PM
Created 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 tablesThis is what made your code work for me
Created 04-07-2017 05:13 AM
I am getting this error while executing your code, could you please let me know if there is some other setup which is required to run this code:
['beeline', '-u', "'jdbc:hive2://<servername>:10000/;ssl=true;", '--fastConnect=true', '--showHeader=false', '--verbose=false', '--showWarnings=false', '--silent=true', '--outputFormat=csv2', '-e', 'use tsz;', '-e', 'show tables;'] No known driver to handle "'jdbc:hive2://<servername>:10000/;ssl=true;" No current connection No current connection Traceback (most recent call last): File "./CheckReconErrors.py", line 53, in <module> tables=beeline.show_tables() File "./CheckReconErrors.py", line 39, in show_tables return self._run_cmd(cmd) File "./CheckReconErrors.py", line 44, in _run_cmd stdout = subprocess.check_call(cmd) File "/usr/lib64/python2.6/subprocess.py", line 505, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '['beeline', '-u', "'jdbc:hive2://<servername>:10000/;ssl=true;", '--fastConnect=true', '--showHeader=false', '--verbose=false', '--showWarnings=false', '--silent=true', '--outputFormat=csv2', '-e', 'use tsz;', '-e', 'show tables;']' returned non-zero exit status 2