from pyhive import hive
import pandas as pd
import numpy as np
class myhive():
def __init__(self,host,port,auth,username,password,database):
self.host=host
self.port=port
self.auth=auth
self.username=username
self.password=password
self.database=database
def Connect(self):
self.conn=hive.connect(host=self.host,port=self.port,auth=self.auth,username=self.username,password=self.password,database=self.database)
#查询数据库表中的所有数据
def Query(self,query_sen):
self.cursor = self.conn.cursor()
self.excute = self.cursor.execute(query_sen)
res = self.cursor.fetchall()
cols=[col[0] for col in cursor.description]
data=pd.DataFrame(np.array(res),columns=cols)
return data
query_sen="select id,pieces_no_id from dp_ods.o_pl_crm_intopieces_dk_s where etl_date='2019-09-05' limit 10"
pyhive=myhive(host=" ",port=10,auth=" ",username=" ",password=" ",database=" ")
hive_connect=pyhive.Connect()
hive_data=pyhive.Query(query_sen)
print(hive_data.head())
手机扫一扫
移动阅读更方便
你可能感兴趣的文章