首页 > 解决方案 > 如何使用 python 加载 Hive 表?

问题描述

我想在 python 中加载我的配置单元表。

我已经尝试使用 pyhive 加载,但它给出了 SASL 代理错误。为此要安装哪些软件包?

标签: pythonhadoophivehdfs

解决方案


您将需要安装:-

pip install sasl
pip install thrift-sasl
pip install thrift
pip install PyHive

现在您必须连接到Hive

from pyhive import hive
conn = hive.Connection(host="URL", port=PORT_NUMBER, username="NAME", password="YOUR_PASSWORD")

建立 hive 连接后,您可以立即运行查询:

cursor = conn.cursor()
cursor.execute("SELECT * FROM table")
print(cur.fetchone())

详情请点击这里

注意:您可以使用连接 (conn) 在 pandas 中创建数据框:

import pandas as pd
df = pd.read_sql("SELECT * FROM table", conn)

推荐阅读