How to Access Hive via Python?

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

    It is a common practice to prohibit for a user to download and install packages and libraries on cluster nodes. In this case solutions of @python-starter and @goks are working perfect, if hive run on the same node. Otherwise, one can use a beeline instead of hive command line tool. See details

    #python 2
    import commands
    
    cmd = 'beeline -u "jdbc:hive2://node07.foo.bar:10000/..." -e "SELECT * FROM db_name.table_name LIMIT 1;"'
    
    status, output = commands.getstatusoutput(cmd)
    
    if status == 0:
       print output
    else:
       print "error"
    

    .

    #python 3
    import subprocess
    
    cmd = 'beeline -u "jdbc:hive2://node07.foo.bar:10000/..." -e "SELECT * FROM db_name.table_name LIMIT 1;"'
    
    status, output = subprocess.getstatusoutput(cmd)
    
    if status == 0:
       print(output)
    else:
       print("error")
    

提交回复
热议问题