How to connect to Hadoop Hive through python via p

2019-07-29 11:52发布

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?

0条回答
登录 后发表回答