几个必要的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()返回当前查询结果集中的下一条数据,如果到达结果集结尾会抛出StopIteration的异常
cursor.fetchone()返回当前查询结果集中的下一条数据,如果到达结果集的尾部返回None
cursor.fetchmany(size=None)返回指定数量的查询结果,如果没有给出size参数,则使用cursor.arraysize(默认值是1000行).如果结果集数据条数
cursor.fetchall()返回查询结果的余下的所有数据,使用此函数要评估数据量,可能会因为数据量太大,导致本地程序内存问题。
cursor.rownumber 属性当读取数据的条数,☞使用cursor.netx(),cursor.fetchone(),cursor.fetchall(),cursor.fetchmany()等方法。
cursor.description查询结果集的元数据,返回结果集有多少列,每个列的列名,数据类型等数据。
cursor.cancel()
取消当前执行的sql
cursor.close()关闭当前游标
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)