要在Python中查詢Hive結果集,您可以使用pyhive庫或pandas庫。
使用pyhive庫:
pip install pyhive
from pyhive import hive
conn = hive.Connection(host="your_hive_host", port=10000, username="your_username", database="your_database")
cursor = conn.cursor()
cursor.execute("SELECT * FROM your_table")
results = cursor.fetchall()
使用pandas庫:
pip install pandas
import pandas as pd
from pyhive import hive
conn = hive.Connection(host="your_hive_host", port=10000, username="your_username", database="your_database")
df = pd.read_sql("SELECT * FROM your_table", conn)
請注意,您需要將"your_hive_host",“your_username”,"your_database"和"your_table"替換為實際的Hive連接和查詢參數。