首先安裝Python包:python
pyhs2項目做者2014年以後就沒有更新了。git
import pyhs2 # PLAIN with pyhs2.connect(host='n5.cluster', port=10000, authMechanism="PLAIN", user='hive', password='hive', database='default') as conn: with conn.cursor() as cur: #Show databases print cur.getDatabases() #Execute query cur.execute("select * from table") #Return column info from query print cur.getSchema() #Fetch table results for i in cur.fetch(): print i
import pyhs2 # KERBEROS conn = pyhs2.connect(host='n5.cluster', port=10000, authMechanism="KERBEROS") conn = pyhs2.connect(host='n5.cluster', port=10000, authMechanism="KERBEROS", user='xwtech/n5.cluster@EXAMPLE.COM', configuration={'krb_host': 'n5.cluster', 'krb_service': 'hive'})