通过Python来操作kylin数据
安装依赖的包(py2/py3都支持)
1 2 3 pip install kylinpy pip install sqlalchemy pip install --upgrade kylinpy
kylinpy工具库包含两个可使用原件. 想要了解更多关于此工具库信息请点击Github仓库 .
Apache Kylin 命令行工具
Apache Kylin SQLAchemy方言
示例代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 import sqlalchemy as sa import kylinpy import pymysql def kylin_query1(conn_str, query_sql): kylin_engine = sa.create_engine(conn_str) print (kylin_engine.table_names()) results = kylin_engine.execute(query_sql) print ([e for e in results]) def kylin_query1(query_sql): kylin = kylinpy.KylinCluster(host =ip, username ="ADMIN" , password ="" , project ="" ) # print (kylin.projects()) results = kylin.query(query_sql) print (results["results" ])if __name__ == "__main__" : conn_str = "kylin://<username>:<password>@<ip>:<port>/<project>?version=<v1|v2>&prefix=</kylin/api>" query_sql = "select userid, datetime, count(*) c from soda_report group by userid, datetime" kylin_query1(conn_str, query_sql) kylin_query2(query_sql)
参考 通过Python来操作kylin
Kylin Python 客户端工具库 - kylinpy