我搜索了几个论坛,无法找到确切的答案。我连接到Hive DB,在Python中运行查询,并将结果导出到.csv但只能返回行,没有列标题。请参阅下面的示例代码。谢谢你的帮助!
import pyhs2
import csv
with pyhs2.connect(host='host',
port=10000,
authMechanism="PLAIN",
user='username',
password='password',
database='default') as conn:
with conn.cursor() as cur:
cur.execute("select * from table limit 100")
result = cur.fetchall()
c = csv.writer(open("temp.csv", "wb"))
for row in result:
c.writerow(row)