python 操作hive pyhs2方式

yipeiwu_com5年前Python基础

使用kerberos时

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
Could not start SASL: Error in sasl_client_start (-1) SASL(-1)

安装

yum install cyrus-sasl-plain cyrus-sasl-devel cyrus-sasl-gssapi

pyhs2 安装 sasl问题

yum install cyrus-sasl-devel 
yum install cyrus-sasl-lib 
yum install libgsasl-devel 
yum install saslwrapper

对接superset hive kerberos

SQLAlchemy URI

hive://herverser2ip:10000/db

扩展 连接参数

{
  "metadata_params": {},
  "engine_params": {
    "connect_args": {
    "auth": "KERBEROS",
        "kerberos_service_name": "hive",
    "username" : "user@KDC.COM"
    }
  }
}

以上这篇python 操作hive pyhs2方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

使用python的pandas为你的股票绘制趋势图

使用python的pandas为你的股票绘制趋势图

前言 手里有一点点公司的股票, 拿不准在什么时机抛售, 程序员也没时间天天盯着看,不如动手写个小程序, 把股票趋势每天早上发到邮箱里,用 python 的 pandas, matplot...

python下调用pytesseract识别某网站验证码的实现方法

一、pytesseract介绍 1、pytesseract说明 pytesseract最新版本0.1.6,网址:https://pypi.python.org/pypi/pytesser...

Python进程间通信之共享内存详解

前一篇博客说了怎样通过命名管道实现进程间通信,但是要在windows是使用命名管道,需要使用python调研windows api,太麻烦,于是想到是不是可以通过共享内存的方式来实现。查...

Python函数和模块的使用总结

函数和模块的使用 在讲解本章节的内容之前,我们先来研究一道数学题,请说出下面的方程有多少组正整数解。 $$x_1 + x_2 + x_3 + x_4 = 8$$ 事实上,上面的问题等同...

python使用点操作符访问字典(dict)数据的方法

本文实例讲述了python使用点操作符访问字典(dict)数据的方法。分享给大家供大家参考。具体分析如下: 平时访问字典使用类似于:dict['name']的方式,如果能通过dict.n...