python连接hive数据库

下载对应的所需包文件
python连接hive数据库_第1张图片

from impala.dbapi import connect
import pandas as pd
import numpy as np
# 连接hive
def LinkHive(sql_select):
    hive_conn = connect(host='192.168.4.216', port=10000, database='dw',user='hive',auth_mechanism='PLAIN')
    cursor = hive_conn.cursor()     
    cursor.execute(sql_select)
    columns = [col[0] for col in cursor.description]
    result = [dict(zip(columns, row)) for row in cursor.fetchall()]
    Main = pd.DataFrame(result)
    Main.columns = columns 
    return Main

你可能感兴趣的:(python常用数据处理场景,python,hive,数据库)