蟒蛇接口

HerePyHive的Python项目详细描述


https://travis-ci.org/dropbox/PyHive.svg?branch=masterhttps://img.shields.io/codecov/c/github/dropbox/PyHive.svg

蜂窝

pyhive是pythonDB-APISQLAlchemy用于PrestoHive

使用量

DB-API

frompyhiveimportpresto# or import hivecursor=presto.connect('localhost').cursor()cursor.execute('SELECT * FROM my_awesome_data LIMIT 10')printcursor.fetchone()printcursor.fetchall()

DB-API(异步)

frompyhiveimporthivefromTCLIService.ttypesimportTOperationStatecursor=hive.connect('localhost').cursor()cursor.execute('SELECT * FROM my_awesome_data LIMIT 10',async=True)status=cursor.poll().operationStatewhilestatusin(TOperationState.INITIALIZED_STATE,TOperationState.RUNNING_STATE):logs=cursor.fetch_logs()formessageinlogs:printmessage# If needed, an asynchronous query can be cancelled at any time with:# cursor.cancel()status=cursor.poll().operationStateprintcursor.fetchall()

sql炼金术

首先安装这个包以向sqlalchemy注册它(请参见setup.py)。

fromsqlalchemyimport*fromsqlalchemy.engineimportcreate_enginefromsqlalchemy.schemaimport*# Prestoengine=create_engine('presto://localhost:8080/hive/default')# Hiveengine=create_engine('hive://localhost:10000/default')logs=Table('my_awesome_data',MetaData(bind=engine),autoload=True)printselect([func.count('*')],from_obj=logs).scalar()

注意:查询生成功能不是详尽的,也不是完全测试过的,但是应该没有 原始SQL有问题。

传递会话配置
# DB-APIhive.connect('localhost',configuration={'hive.exec.reducers.max':'123'})presto.connect('localhost',session_props={'query_max_run_time':'1234m'})# SQLAlchemycreate_engine('presto://user@host:443/hive',connect_args={'protocol':'https','session_props':{'query_max_run_time':'1234m'}})create_engine('hive://user@host:10000/database',connect_args={'configuration':{'hive.exec.reducers.max':'123'}},)# SQLAlchemy with LDAPcreate_engine('hive://user:password@host:10000/database',connect_args={'auth':'LDAP'},)

要求

使用安装

  • pip install pyhive[hive]用于配置单元接口和
  • pip install pyhive[presto]用于presto接口。

pyhive与

  • python 2.7/python 3
  • 对于presto:presto安装
  • 对于配置单元:HiveServer2守护进程

贡献

  • 请在https://opensource.dropbox.com/cla/填写Dropbox Contributor许可协议,并在请求中注意这一点。
  • 更改必须附带测试,除了一些琐碎的事情,比如修复注释。有关测试环境设置,请参见.travis.yml。
  • 项目范围说明:
    • 这个项目旨在成为一个最小的hive/presto客户机,它只做一件事而不做其他事情。 可以在pyhive之上实现的特性,例如与您喜爱的数据分析库的集成,可能超出了范围。
    • 我们倾向于在大量专业化的、不灵活的特征上拥有少量的通用特征。 例如,presto代码使用任意的requests_session参数定制http调用,而不是为每个requests选项使用单独的参数/分支。

测试

https://travis-ci.org/dropbox/PyHive.svghttp://codecov.io/github/dropbox/PyHive/coverage.svg?branch=master

在具有hive/presto的环境中运行以下命令:

./scripts/make_test_tables.sh
virtualenv --no-site-packages env
source env/bin/activate
pip install -e .
pip install -r dev_requirements.txt
py.test

警告:这将删除/创建名为one_rowone_row_complexmany_rows的表,并加上 数据库名为pyhive_test_database

更新tcliservice

tcliservice模块是使用TCLIService.thrift文件自动生成的。为了更新它, generate.py文件可以使用:python generate.py <TCLIServiceURL>。当留空时, 将下载配置单元2.3的版本。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java<E extends Number>和<Number>之间有什么区别?   java如何将ActionScriptObject转换为ByteArray?   java如何平衡图形中的循环?   java为什么会抛出这个SAXParsexException?   使用JPA的java删除实体   java为什么要使用AccessibilityManager是有原因的。sInstance会导致内存泄漏吗?   java如何在Spring表单中隐藏选项?   java简单Hello World servlet在EclipseTomcat中给出错误404   java解决Web应用程序的heapdump问题(JSP+SpringMVC+JPAHIBERNATE)   SpringBoot如何为java联合生成graphql模式?   java是否将用户输入(从TextField)传递到另一个类?   java如何对集合执行clone()。newSetFromMap(地图)   java节点JS服务器处理10000个WebSocket   java为什么Thymeleaf International仅适用于ResourceBundleMessageSource   java如何使用build编译ResourceBundle类。xml文件   Java 2D游戏检查玩家是否触摸到另一个精灵   java无法从类<PowerMockRunner>转换为类<?扩展Runner>   从服务器搜索json数组的java搜索栏   java通过无知解决LazyInitializationException异常   java从线程更新JFreeChart