The future of you, waiting for you in the future.

Geoffrey

Long, long the pathway to Cold Hill;
Drear, drear the waterside so chill.

返回顶部

Python 连接 impala

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")
posted @ 2021-05-06 22:55  Geoffreygau  阅读(447)  评论(0编辑  收藏  举报