无法使用impyla / dbapi.py使用python连接到配置单元

问题描述 投票:0回答:1

我正在尝试使用python连接到hive [使用默认的derby db]:

from impala.dbapi import connect
conn = connect( host='localhost', port=10000)
cursor = conn.cursor()
cursor.execute('SELECT * FROM employee')
print cursor.description  # prints the result set's schema
results = cursor.fetchall()

但我收到错误:

Traceback (most recent call last):
  File "hivetest_b.py", line 2, in <module>
    conn = connect( host='localhost', port=10000)
  File "/home/ubuntu/.local/lib/python2.7/site-packages/impala/dbapi.py", line 147, in connect
    auth_mechanism=auth_mechanism)
  File "/home/ubuntu/.local/lib/python2.7/site-packages/impala/hiveserver2.py", line 758, in connect
    transport.open()
  File "/home/ubuntu/.local/lib/python2.7/site-packages/thrift/transport/TTransport.py", line 149, in open
    return self.__trans.open()
  File "/home/ubuntu/.local/lib/python2.7/site-packages/thrift/transport/TSocket.py", line 101, in open
    message=message)
thrift.transport.TTransport.TTransportException: Could not connect to localhost:10000

我的/ etc / hosts中的条目是:

127.0.0.1 localhost

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

我使用默认的hive-site.xml和默认的derby数据库来运行我的配置单元。当我通过shell运行配置单元时它向我显示该表:

hive> show databases;
OK
default
test
test_db
Time taken: 0.937 seconds, Fetched: 3 row(s)
hive> show tables;
OK
employee
Time taken: 0.054 seconds, Fetched: 1 row(s)
hive> describe employee;
OK
empname                 string
age                     int
gender                  string
income                  float
department              string
dept                    string

# Partition Information
# col_name              data_type               comment

dept                    string
Time taken: 0.451 seconds, Fetched: 11 row(s)

我不确定我到底错过了什么。任何快速参考/指针将不胜感激。

此致,Bhupesh

python python-2.7 hadoop hive hadoop2
1个回答
0
投票

您可以使用以下命令检查和验证端口:

hive> set hive.server2.thrift.port;

并尝试使用0.0.0.0127.0.0.1而不是localhost作为连接的主机。

© www.soinside.com 2019 - 2024. All rights reserved.