How to connect to Hadoop Hive through python via pyhs2?

99封情书 提交于 2019-12-24 07:35:58

问题


I've installed Hadoop eco system on OS X. And I have installed pyhs2 python package in order to connect to hive and query the database. The code I use is as below:

import pyhs2


with pyhs2.connect(host='127.0.0.1',
                   port=10000,
                   authMechanism="PLAIN",
                   user='admin',
                   password='1234qwer',
                   database='cards') as conn:
    with conn.cursor() as cur:
        #Show databases
        print cur.getDatabases()

        #Execute query
        cur.execute("select * from users")

        #Return column info from query
        print cur.getSchema()

        #Fetch table results
        for i in cur.fetch():
            print i

In hive config file /usr/local/opt/hive/libexec/conf/hive-default.xml I have set username and password to admin and 1234qwer.

Now when I run the python script it gives the below error:

thrift.transport.TTransport.TTransportException: Could not connect to 127.0.0.1:10000

Similar question in stack overflow:

How to connect to hive using python pyhs2?

I can go to hive through terminal and all things work as expected.

The weird thing is that I checked whether port 10000 is open or not by using lsof -i -P | grep -i 'listen'" but the port is not listed there!

Any help?

来源:https://stackoverflow.com/questions/38953764/how-to-connect-to-hadoop-hive-through-python-via-pyhs2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!