python – 连接到HiveServer2时impyla挂起
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python – 连接到HiveServer2时impyla挂起,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1659字,纯文字阅读大概需要3分钟。
内容图文
我正在用Python编写一些ETL流程,对于部分流程,我们使用Hive.根据documentation,Cloudera的impyla客户端与Impala和Hive一起工作.
根据我的经验,客户端为Impala工作,但在我尝试连接到Hive时挂起:
from impala.dbapi import connect
conn = connect(host='host_running_hs2_service', port=10000, user='awoolford', password='Bzzzzz')
cursor = conn.cursor() <- hangs here
cursor.execute('show tables')
results = cursor.fetchall()
print results
如果我逐步进入代码,它会在尝试打开会话时挂起(line #873 of hiveserver2.py).
起初,我怀疑防火墙端口可能阻止连接,所以我尝试使用Java连接.令我惊讶的是,这有效:
public class Main {
private static String driverName = "org.apache.hive.jdbc.HiveDriver";
public static void main(String[] args) throws SQLException {
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.exit(1);
}
Connection connection = DriverManager.getConnection("jdbc:hive2://host_running_hs2_service:10000/default", "awoolford", "Bzzzzz");
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SHOW TABLES");
while (resultSet.next()) {
System.out.println(resultSet.getString(1));
}
}
}
由于Hive和Python是如此常用的技术,我很想知道是否有其他人遇到过这个问题,如果有的话,你做了什么修复它?
版本:
> Hive 1.1.0-cdh5.5.1
> Python 2.7.11 | Anaconda 2.3.0
> Redhat 6.7
解决方法:
/path/to/bin/hive --service hiveserver2 --hiveconf hive.server2.authentication=NOSASL
from impala.dbapi import connect
conn = connect(host='host_running_hs2_service', port=10000, user='awoolford', password='Bzzzzz', auth_mechanism='NOSASL')
cursor = conn.cursor()
cursor.execute('show tables')
results = cursor.fetchall()
print results
内容总结
以上是互联网集市为您收集整理的python – 连接到HiveServer2时impyla挂起全部内容,希望文章能够帮你解决python – 连接到HiveServer2时impyla挂起所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。