All Projects → dropbox → Pyhive

dropbox / Pyhive

Licence: other
Python interface to Hive and Presto. 🐝

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Pyhive

Cube.js
📊 Cube — Open-Source Analytics API for Building Data Apps
Stars: ✭ 11,983 (+769.59%)
Mutual labels:  hive, presto
dpkb
大数据相关内容汇总,包括分布式存储引擎、分布式计算引擎、数仓建设等。关键词:Hadoop、HBase、ES、Kudu、Hive、Presto、Spark、Flink、Kylin、ClickHouse
Stars: ✭ 123 (-91.07%)
Mutual labels:  presto, hive
Presto
The official home of the Presto distributed SQL query engine for big data
Stars: ✭ 12,957 (+840.28%)
Mutual labels:  hive, presto
Haproxy Configs
80+ HAProxy Configs for Hadoop, Big Data, NoSQL, Docker, Elasticsearch, SolrCloud, HBase, MySQL, PostgreSQL, Apache Drill, Hive, Presto, Impala, Hue, ZooKeeper, SSH, RabbitMQ, Redis, Riak, Cloudera, OpenTSDB, InfluxDB, Prometheus, Kibana, Graphite, Rancher etc.
Stars: ✭ 106 (-92.31%)
Mutual labels:  hive, presto
Trino
Official repository of Trino, the distributed SQL query engine for big data, formerly known as PrestoSQL (https://trino.io)
Stars: ✭ 4,581 (+232.44%)
Mutual labels:  hive, presto
Linkis
Linkis helps easily connect to various back-end computation/storage engines(Spark, Python, TiDB...), exposes various interfaces(REST, JDBC, Java ...), with multi-tenancy, high performance, and resource control.
Stars: ✭ 2,323 (+68.58%)
Mutual labels:  hive, presto
Bigdata docker
Big Data Ecosystem Docker
Stars: ✭ 161 (-88.32%)
Mutual labels:  hive, presto
TiBigData
TiDB connectors for Flink/Hive/Presto
Stars: ✭ 192 (-86.07%)
Mutual labels:  presto, hive
incubator-linkis
Linkis helps easily connect to various back-end computation/storage engines(Spark, Python, TiDB...), exposes various interfaces(REST, JDBC, Java ...), with multi-tenancy, high performance, and resource control.
Stars: ✭ 2,459 (+78.45%)
Mutual labels:  presto, hive
databricks-dbapi
DBAPI and SQLAlchemy dialect for Databricks Workspace and SQL Analytics clusters
Stars: ✭ 21 (-98.48%)
Mutual labels:  sqlalchemy, hive
Databook
A facebook for data
Stars: ✭ 26 (-98.11%)
Mutual labels:  sqlalchemy, hive
Yanagishima
Web UI for Trino, Presto, Hive, Elasticsearch, SparkSQL
Stars: ✭ 424 (-69.23%)
Mutual labels:  hive, presto
Maha
A framework for rapid reporting API development; with out of the box support for high cardinality dimension lookups with druid.
Stars: ✭ 101 (-92.67%)
Mutual labels:  hive, presto
Hadoop cookbook
Cookbook to install Hadoop 2.0+ using Chef
Stars: ✭ 82 (-94.05%)
Mutual labels:  hive
Markbj
一个开放的知识社区
Stars: ✭ 94 (-93.18%)
Mutual labels:  sqlalchemy
Docker Trino Cluster
Multiple node presto cluster on docker container
Stars: ✭ 81 (-94.12%)
Mutual labels:  presto
Data Driven Web Apps With Pyramid And Sqlalchemy
Demos and handouts for Talk Python's Data-Driven Web Apps with Pyramid and SQLAlchemy course
Stars: ✭ 79 (-94.27%)
Mutual labels:  sqlalchemy
Bigdata Notes
大数据入门指南 ⭐
Stars: ✭ 10,991 (+697.61%)
Mutual labels:  hive
Bitalarm
An app to keep track of different cryptocurrencies, written in dart + flutter
Stars: ✭ 94 (-93.18%)
Mutual labels:  hive
Sqlalchemy Hana
SQLAlchemy Dialect for SAP HANA
Stars: ✭ 75 (-94.56%)
Mutual labels:  sqlalchemy

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

====== PyHive

PyHive is a collection of Python DB-API <http://www.python.org/dev/peps/pep-0249/>_ and SQLAlchemy <http://www.sqlalchemy.org/>_ interfaces for Presto <http://prestodb.io/>_ and Hive <http://hive.apache.org/>_.

Usage

DB-API

.. code-block:: python

from pyhive import presto  # or import hive or import trino
cursor = presto.connect('localhost').cursor()
cursor.execute('SELECT * FROM my_awesome_data LIMIT 10')
print cursor.fetchone()
print cursor.fetchall()

DB-API (asynchronous)

.. code-block:: python

from pyhive import hive
from TCLIService.ttypes import TOperationState
cursor = hive.connect('localhost').cursor()
cursor.execute('SELECT * FROM my_awesome_data LIMIT 10', async=True)

status = cursor.poll().operationState
while status in (TOperationState.INITIALIZED_STATE, TOperationState.RUNNING_STATE):
    logs = cursor.fetch_logs()
    for message in logs:
        print message

    # If needed, an asynchronous query can be cancelled at any time with:
    # cursor.cancel()

    status = cursor.poll().operationState

print cursor.fetchall()

In Python 3.7 async became a keyword; you can use async_ instead:

.. code-block:: python

cursor.execute('SELECT * FROM my_awesome_data LIMIT 10', async_=True)

SQLAlchemy

First install this package to register it with SQLAlchemy (see setup.py).

.. code-block:: python

from sqlalchemy import *
from sqlalchemy.engine import create_engine
from sqlalchemy.schema import *
# Presto
engine = create_engine('presto://localhost:8080/hive/default')
# Trino
engine = create_engine('trino://localhost:8080/hive/default')
# Hive
engine = create_engine('hive://localhost:10000/default')
logs = Table('my_awesome_data', MetaData(bind=engine), autoload=True)
print select([func.count('*')], from_obj=logs).scalar()

Note: query generation functionality is not exhaustive or fully tested, but there should be no problem with raw SQL.

Passing session configuration

.. code-block:: python

# DB-API
hive.connect('localhost', configuration={'hive.exec.reducers.max': '123'})
presto.connect('localhost', session_props={'query_max_run_time': '1234m'})
trino.connect('localhost',  session_props={'query_max_run_time': '1234m'})
# SQLAlchemy
create_engine(
    'presto://[email protected]:443/hive',
    connect_args={'protocol': 'https',
                  'session_props': {'query_max_run_time': '1234m'}}
)
create_engine(
    'trino://[email protected]:443/hive',
    connect_args={'protocol': 'https',
                  'session_props': {'query_max_run_time': '1234m'}}
)
create_engine(
    'hive://[email protected]:10000/database',
    connect_args={'configuration': {'hive.exec.reducers.max': '123'}},
)
# SQLAlchemy with LDAP
create_engine(
    'hive://user:[email protected]:10000/database',
    connect_args={'auth': 'LDAP'},
)

Requirements

Install using

  • pip install 'pyhive[hive]' for the Hive interface and
  • pip install 'pyhive[presto]' for the Presto interface.
  • pip install 'pyhive[trino]' for the Trino interface

PyHive works with

  • Python 2.7 / Python 3
  • For Presto: Presto install
  • For Trino: Trino install
  • For Hive: HiveServer2 <https://cwiki.apache.org/confluence/display/Hive/Setting+up+HiveServer2>_ daemon

Changelog

See https://github.com/dropbox/PyHive/releases.

Contributing

  • Please fill out the Dropbox Contributor License Agreement at https://opensource.dropbox.com/cla/ and note this in your pull request.

  • Changes must come with tests, with the exception of trivial things like fixing comments. See .travis.yml for the test environment setup.

  • Notes on project scope:

    • This project is intended to be a minimal Hive/Presto client that does that one thing and nothing else. Features that can be implemented on top of PyHive, such integration with your favorite data analysis library, are likely out of scope.
    • We prefer having a small number of generic features over a large number of specialized, inflexible features. For example, the Presto code takes an arbitrary requests_session argument for customizing HTTP calls, as opposed to having a separate parameter/branch for each requests option.

Testing

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

Run the following in an environment with 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

WARNING: This drops/creates tables named one_row, one_row_complex, and many_rows, plus a database called pyhive_test_database.

Updating TCLIService

The TCLIService module is autogenerated using a TCLIService.thrift file. To update it, the generate.py file can be used: python generate.py <TCLIServiceURL>. When left blank, the version for Hive 2.3 will be downloaded.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].