用impyla可以访问impala和hive,连接方式比较简单,对于安全集群,认证方式可以支持kerberos和LDAP,直接上代码。
用impyla连接HIVE (kerberos协议连接)
from impala.dbapi import connect
conn = connect(host=[hive server host/ip],port=10000,database='default',auth_mechanism='GSSAPI',kerberos_service_name='hive')
cursor = conn.cursor()
cursor.execute('show tables')
res = cursor.fetchall()
print res
用impyla连接IMPALA (kerberos协议连接)
from impala.dbapi import connect
conn = connect(host=[impala server host/ip],port=21050,database='default',auth_mechanism='GSSAPI',kerberos_service_name='impala')
cursor = conn.cursor()
cursor.execute('show tables')
res = cursor.fetchall()
print res
用impyla连接HIVE (LDAP协议连接)
from impala.dbapi import connect
conn = connect(host=[hive server host/ip],port=10000,database='default',use_ssl=False,auth_mechanism='PLAIN',user='userAdmin',password='******')
cursor = conn.cursor()
cursor.execute('show tables')
res = cursor.fetchall()
print res
用impyla连接IMPALA (LDAP协议连接)
from impala.dbapi import connect
conn = connect(host=[impala server host/ip],port=21050,database='default',use_ssl=False,auth_mechanism='PLAIN',user='userAdmin',password='******')
cursor = conn.cursor()
cursor.execute('show tables')
res = cursor.fetchall()
print res