Python连接Hive数据库
Posted 二哥不像程序员
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python连接Hive数据库相关的知识,希望对你有一定的参考价值。
import pyhive
from pyhive import hive
import pandas as pd
import key_one
class LinkHive(object):
def __init__(self,host,port,username,password,database):
self.host = host
self.port = port
self.username = username
self.password = password
self.database = database
def __link(self):
self.conn = hive.Connection(host=self.host,
port=10000,
username=self.username,
password=self.password,
database=self.database,
auth='CUSTOM')
# CUSTOM LDAP
def selectdata(self,sql):
self.__link()
return pd.read_sql(sql,self.conn)
if __name__ == "__main__":
sql = "show tables"
result = LinkHive(host = key_one.host,port = key_one.port,username = key_one.username,
password = key_one.password,database='kkb_da').selectdata(sql)
result
以上是关于Python连接Hive数据库的主要内容,如果未能解决你的问题,请参考以下文章