impyla安装过程
# 安装依赖
pip install bit_array
pip install thrift
pip install thriftpy
pip install pure_sasl
pip install --no-deps thrift-sasl==0.2.1
## 安装impyla
pip install impyla
连接impala
from impala.dbapi import connect
conn = connect(host='IP_ADDRESS',
port=21050,
# database="snap",
user="root",
password="123456",
auth_mechanism='NOSASL'
)
cur = conn.cursor()
cur.execute("""SELECT * FROM `db_name`.`table_name` LIMIT 10""")
# 获取字段名
des = cur.description
cols = [item[0] for item in des]
# 获取数据
data_list=cur.fetchall()
# 导出 csv
import pandas as pd
data = pd.DataFrame(data_list, columns=cols)
# data.to_csv("table_name.csv", encoding="utf_8_sig")