python - impyla 在连接到 HiveServer2 时挂起

标签 python hive

我正在用 Python 编写一些 ETL 流程,其中部分流程使用 Hive。 Cloudera 的 impyla 客户端,根据 documentation , 适用于 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

如果我单步执行代码,它会在尝试打开 session 时挂起 (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 是常用的技术,我很想知道是否有其他人遇到过这个问题,如果遇到过,您是如何解决的?

版本:

  • 配置单元 1.1.0-cdh5.5.1
  • Python 2.7.11 | python 2.3.0
  • 红帽 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 - impyla 在连接到 HiveServer2 时挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35854145/

相关文章:

ubuntu - 在 Ubuntu : $HADOOP_HOME or $HADOOP_PREFIX must be set or hadoop must be in the 上安装 Hive 的问题

hadoop - 将参数传递给 sqoop 作业

python - 替换 Pandas 列中的第一个单词

python - 在 python pandas 中将多个年份列转换为单个年份列(整洁格式)

python - 错误 : OSError: libmediainfo. so.0:无法打开共享对象文件:没有这样的文件或目录

hive - 将 Ascii 值转换为配置单元中的字符

sql - Informix 到 HiveQL

hadoop - Hive Oozie 错误处理

python - 当模板存在时,为什么 rst2pdf 会给出 TemplateNotFound 错误?

python - Dask 广播在计算图中不可用