1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
import pyhs2
class HiveClient: def __init__(self, db_host, user, password, database, port=10000, authMechanism="PLAIN"): self.conn = pyhs2.connect(host=db_host, port=port, authMechanism=authMechanism, user=user, password=password, database=database, )
def query(self, sql): with self.conn.cursor() as cursor: cursor.execute(sql) return cursor.fetch()
def close(self): self.conn.close()
def main(): hive_client = HiveClient(db_host='127.0.0.1', port=10000, user='root', password='root123456', database='default', authMechanism='PLAIN') result = hive_client.query('select * from test limit 10') print result hive_client.close()
if __name__ == '__main__': main()
|