Python链接到HiveServer2

环境配置

首先安装Python包:python

  • sasl
  • pyhs2

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

使用KERBEROS

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'})

pyhs2地址

https://github.com/BradRuderman/pyhs2/github

相关文章
相关标签/搜索