Python实现pyhs2的JDCB链接Hive

# -*- coding:utf-8 -*-
__author__ = 'yangxin_ryan'
import pyhs2
"""
hive客户端
"""


class HiveClient(object):

    def __init__(self, host, port, user_name, password, database, authMechanism):
        self.conn = pyhs2.connect(host=host,
                                  port=port,
                                  authMechanism=authMechanism,
                                  user=user_name,
                                  password=password,
                                  database=database)

    # 查询方法
    def query_data(self, sql):
        with self.conn.cursor() as cursor:
            cursor.execute(sql)
            return cursor.fetch()

    # 插入方法
    def insert_data(self, sql):
        with self.conn.cursor() as cursor:
            result = cursor.execute(sql)
            return result

    def close(self):
        self.conn.close()


if __name__ == '__main__':
    hive_client = HiveClient("127.0.0.1", 10000, "hdfs", "hdfs", "default", "PLAIN")
    sql = "insert into table temp.xxxx partition(dt='2019-06-05') values('xx', 'xx', 'xx', 'xxxxx')"
    hive_client.insert_data(sql)

 

你可能感兴趣的:(Python)