python操作HIVE的方法

使用HIVE2.3.6,Python3.7

使用pyhive,可以成功连接的hive和操作

直接上代码

from pyhive import hive
from pyhive.exc import OperationalError

class HiveControl:

    def __init__(self, db_name='default'):
        self.conn = hive.connect(host=settings.HIVE_HOST, port=settings.HIVE_PORT,
                                 username=settings.HIVE_USER, auth=settings.HIVE_AUTH, database=db_name)
        self.cursor = self.conn.cursor()

   def create_table(self):
        
        sql='show databases'

        try:
            self.cursor.execute(sql)
        except OperationalError as err:
            print(err)
            return False
        else:
            print('OK')
            return True
原文地址:https://www.cnblogs.com/hupingzhi/p/12600778.html