How to Access Hive via Python?

后端 未结 16 874
小蘑菇
小蘑菇 2020-11-30 17:11

https://cwiki.apache.org/confluence/display/Hive/HiveClient#HiveClient-Python appears to be outdated.

When I add this to /etc/profile:

export PYTHONP         


        
16条回答
  •  长情又很酷
    2020-11-30 17:37

    By using Python Client Driver

    pip install pyhs2
    

    Then

    import pyhs2
    
    with pyhs2.connect(host='localhost',
                   port=10000,
                   authMechanism="PLAIN",
                   user='root',
                   password='test',
                   database='default') as conn:
    with conn.cursor() as cur:
        #Show databases
        print cur.getDatabases()
    
        #Execute query
        cur.execute("select * from table")
    
        #Return column info from query
        print cur.getSchema()
    
        #Fetch table results
        for i in cur.fetch():
            print i
    

    Refer : https://cwiki.apache.org/confluence/display/Hive/Setting+Up+HiveServer2#SettingUpHiveServer2-PythonClientDriver

提交回复
热议问题