Skip to main content
 首页 » 编程设计

Python Hive 客户端 pyhs2 : How to return results from a select statement

2025年05月04日12mfryf

下面是我的代码:

 import pyhs2 
 
 with pyhs2.connect(host='localhost', 
               port=10000, 
               authMechanism="PLAIN", 
               user='biuser', 
               password='biuser', 
               database='default') as conn: 
    with conn.cursor() as cur: 
 
        #Execute query 
        cur.execute("select * from some_table") 
        print "executed" 
        #Fetch table results 
        for i in cur.fetch(): 
            print i 

上面的代码在打印“executed”后继续运行,看不到尽头!应该花那么多时间吗?其他像获取各种数据库名称和获取所有表名称等执行不会花费太多时间。您如何在此处捕获 select 语句的结果?

请您参考如下方法:

这应该适合你;将 for 循环替换为:

while cur.hasMoreRows: 
    print cur.fetchone()