How to Access Hive via Python?

后端 未结 16 850
小蘑菇
小蘑菇 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:54

    None of the answers demonstrate how to fetch and print the table headers. Modified the standard example from PyHive which is widely used and actively maintained.

    from pyhive import hive
    cursor = hive.connect(host="localhost", 
                          port=10000, 
                          username="shadan", 
                          auth="KERBEROS", 
                          kerberos_service_name="hive"
                          ).cursor()
    cursor.execute("SELECT * FROM my_dummy_table LIMIT 10")
    columnList = [desc[0] for desc in cursor.description]
    headerStr = ",".join(columnList)
    headerTuple = tuple(headerStr.split (",")
    print(headerTuple)
    print(cursor.fetchone())
    print(cursor.fetchall())
    

提交回复
热议问题