python操作hive

pyhive配置,参考博文:

https://blog.csdn.net/u010916338/article/details/97283211 

from pyhive import hive


#获取Hive连接
def getHiveConn():
    conn = None
    try:
        conn = hive.Connection(host='20.58.32.9', port=10000, username='hive', database='risk')
    except Exception as e:
        print(e)
    return conn



#读取Hive数据
def readDataFromHive(conn, sql):
    curosr = conn.cursor()
    print(sql)
    curosr.execute(sql)
    result = curosr.fetchall()
    df = pd.DataFrame(result)
    return df



#执行hiveSQL
def executeHiveSQL(conn, sql):
    curosr = conn.cursor()
    print(sql)
    curosr.execute(sql)



#关闭Hive数据连接
def closeHiveConn(conn):
    if conn != None:
        conn.close()

 

你可能感兴趣的:(pyhive,hive)