It is a common practice to prohibit for a user to download and install packages and libraries on cluster nodes. In this case solutions of @python-starter and @goks are working perfect, if hive run on the same node. Otherwise, one can use a beeline
instead of hive
command line tool. See details
#python 2
import commands
cmd = 'beeline -u "jdbc:hive2://node07.foo.bar:10000/...<your connect string>" -e "SELECT * FROM db_name.table_name LIMIT 1;"'
status, output = commands.getstatusoutput(cmd)
if status == 0:
print output
else:
print "error"
.
#python 3
import subprocess
cmd = 'beeline -u "jdbc:hive2://node07.foo.bar:10000/...<your connect string>" -e "SELECT * FROM db_name.table_name LIMIT 1;"'
status, output = subprocess.getstatusoutput(cmd)
if status == 0:
print(output)
else:
print("error")