成都网站建设设计

将想法与焦点和您一起共享

python操作hivepyhs2方式-创新互联

使用kerberos时

专注于为中小企业提供成都网站设计、做网站服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业晋江免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了上1000+企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
import pyhs2

class HiveClient:
  # 初始化
  def __init__(self, db_host, user, password, database, port=10000, authMechanism="PLAIN", configuration=None):
    self.conn = pyhs2.connect(host=db_host,
                 port=port,
                 authMechanism=authMechanism,
                 user=user,
                 password=password,
                 database=database,
                 configuration=configuration,
                 )

  # 查询方法
  def query(self, sql):
    with self.conn.cursor() as cursor:
      cursor.execute(sql)
      return cursor.fetch()

  def close(self):
    self.conn.close()


def getHiveData(sql):
  config = {"mapreduce.job.queuename": "default", 'krb_host': 'hiveserve2ip', 'krb_service': 'hive'}
  hive_client = HiveClient(db_host='hiveserve2ip', port=10000, user='user@kdc.com', password='hive', database='dw.usee',
               authMechanism='KERBEROS', configuration=config)
  print sql
  result = hive_client.query(sql)
  return result

网站标题:python操作hivepyhs2方式-创新互联
链接分享:http://chengdu.cdxwcx.cn/article/sphps.html