Member since
04-08-2016
7
Posts
2
Kudos Received
0
Solutions
01-07-2017
08:58 AM
pyhs2 can't support Python 3.
... View more
01-07-2017
08:56 AM
1 Kudo
@siddharth peesary 1. You must install kerberos client on your PC. 2. You mast get and kinit a ticket for kerberos. 3. And then you must install Pyhive model. 4. Then test.py like this: #!/usr/bin/env python
# -*- coding: utf-8 -*-
# hive util with hive server2
from impala.dbapi import connect
class HiveClient:
def __init__(self, db_host, port, authMechanism, user, password, database, kbservice):
self.conn = connect(host=db_host,
port=port,
auth_mechanism=authMechanism,
user=user,
password=password,
database=database,
kerberos_service_name=kbservice
)
def query(self, sql):
with self.conn.cursor() as cursor:
cursor.execute(sql)
return cursor.fetchall()
def close(self):
self.conn.close()
if __name__ == '__main__':
hive_client = HiveClient(db_host='namenode02.xxx.com', port=10000, authMechanism='GSSAPI', user='hive', password='',
database='data_mp_raw', kbservice='hive')
sql = "select dt, hour, vid, sum(1) as play_num from tbl_mp_stream where dt='20161204' and hour='12' and vid is not null group by dt, hour, vid order by play_num desc limit 50"
sql = "SHOW TABLES"
result = hive_client.query(sql)
hive_client.close()
for x in result:
print(x)
5. The result like this( My python version is 3.5.2 )
... View more