python连接hive--Pyhive

Pyhive

安装包

pip install sasl
pip install thrift
pip install thrift-sasl
pip install PyHive
# 安装对应的包  sasl可能会报错
#下载sasl文件

sasl下载

执行语句

第一种
from pyhive import hive
def select_pyhive(sql):
    # 创建hive连接
    conn = hive.Connection(host='##', port=##, username='##', database='库名')
    cur = conn.cursor()
    try:
        # c = cur.fetchall()
        df = pd.read_sql(sql, conn)
        return df
    finally:
        if conn:
            conn.close()
sql='select * from table limit 10'
df = select_pyhive(sql)
第二种
from sqlalchemy.engine import create_engine
def _sql_hive():
    engine = create_engine(
        'aaaaa://host:port/hive/')
    df = pd.read_sql("""
          select * from table limit 100
    """, engine)
    return df
df = _sql_hive()

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