几个必要的pip,如果用anaconda 安装pyhive的时候会附带都给安装上
pip install pyhive
pip install thrift
pip install sasl
pip install thrift-compiler
pip install thrift-sasl
from pyhive import hive
import pandas as pd
#通过HIVE链接
cursor = hive.connect(host=' ',port=10000, auth='LDAP', database=' ', username=' ', password=' ').cursor()
cursor.execute('select * from table')
#fetchall()返回查询结果的余下的所有数据,使用此函数要评估数据量,可能会因为数据量太大,导致本地程序内存问题。
#cursor.description 查询结果集的元数据,返回结果集有多少列,每个列的列名,数据类型等数据。dataframe引用结果集为列名
data = cursor.fetchall()
columns = [col[0].split('.')[-1] for col in cursor.description]
data = pd.DataFrame(data=data, columns=columns)
print(data)
cursor.execute(operation, params)
可以直接是执行sql查询语句
cursor.next()
返回当前查询结果集中的下一条数据