连接到HiveServer2时impyla挂起

时间:2016-03-07 21:13:45

标签: python hive

我正在用Python编写一些ETL流程,对于部分流程,使用Hive。根据{{​​3}},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

如果我进入代码,它会在尝试打开会话时挂起(documentation)。

起初,我怀疑防火墙端口可能会阻止连接,因此我尝试使用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

3 个答案:

答案 0 :(得分:1)

/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

答案 1 :(得分:0)

我尝试了Dropbox的PyHive包,它运行得很好:

utf-8

我不确定为什么Impyla客户端不起作用,但至少我们可以继续前进。

答案 2 :(得分:0)

/etc/hive/conf/hive-site.xml中添加以下代码对我有用:

<property>
  <name>hive.server2.authentication</name>
  <value>NOSASL</value>
</property>

感谢@ ozw1z5rd的评论为我指出了正确的方向!

相关问题