PyHive-0.6.3-fix-sqlalchemy2.0


NamePyHive-0.6.3-fix-sqlalchemy2.0 JSON
Version 0.6.3.dev0 PyPI version JSON
download
home_pagehttps://github.com/dropbox/PyHive
SummaryPython interface to Hive
upload_time2023-06-19 09:06:34
maintainer
docs_urlNone
authorJing Wang
requires_python
licenseApache License, Version 2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage
            ================================
Project is currently unsupported
================================




.. 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()

    # Hive + HTTPS + LDAP or basic Auth
    engine = create_engine('hive+https://username:password@localhost:10000/')
    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://user@host:443/hive',
        connect_args={'protocol': 'https',
                      'session_props': {'query_max_run_time': '1234m'}}
    )
    create_engine(
        'trino://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 LDAP
    create_engine(
        'hive://user:password@host: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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/dropbox/PyHive",
    "name": "PyHive-0.6.3-fix-sqlalchemy2.0",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Jing Wang",
    "author_email": "jing@dropbox.com",
    "download_url": "https://files.pythonhosted.org/packages/b2/c3/5a6a63937769a6378a095bacb5587ace0728c61c26036b7bfd589e429833/PyHive_0.6.3_fix_sqlalchemy2.0-0.6.3.dev0.tar.gz",
    "platform": null,
    "description": "================================\nProject is currently unsupported\n================================\n\n\n\n\n.. image:: https://travis-ci.org/dropbox/PyHive.svg?branch=master\n    :target: https://travis-ci.org/dropbox/PyHive\n.. image:: https://img.shields.io/codecov/c/github/dropbox/PyHive.svg\n\n======\nPyHive\n======\n\nPyHive is a collection of Python `DB-API <http://www.python.org/dev/peps/pep-0249/>`_ and\n`SQLAlchemy <http://www.sqlalchemy.org/>`_ interfaces for `Presto <http://prestodb.io/>`_ and\n`Hive <http://hive.apache.org/>`_.\n\nUsage\n=====\n\nDB-API\n------\n.. code-block:: python\n\n    from pyhive import presto  # or import hive or import trino\n    cursor = presto.connect('localhost').cursor()\n    cursor.execute('SELECT * FROM my_awesome_data LIMIT 10')\n    print cursor.fetchone()\n    print cursor.fetchall()\n\nDB-API (asynchronous)\n---------------------\n.. code-block:: python\n\n    from pyhive import hive\n    from TCLIService.ttypes import TOperationState\n    cursor = hive.connect('localhost').cursor()\n    cursor.execute('SELECT * FROM my_awesome_data LIMIT 10', async=True)\n\n    status = cursor.poll().operationState\n    while status in (TOperationState.INITIALIZED_STATE, TOperationState.RUNNING_STATE):\n        logs = cursor.fetch_logs()\n        for message in logs:\n            print message\n\n        # If needed, an asynchronous query can be cancelled at any time with:\n        # cursor.cancel()\n\n        status = cursor.poll().operationState\n\n    print cursor.fetchall()\n\nIn Python 3.7 `async` became a keyword; you can use `async_` instead:\n\n.. code-block:: python\n\n    cursor.execute('SELECT * FROM my_awesome_data LIMIT 10', async_=True)\n\n\nSQLAlchemy\n----------\nFirst install this package to register it with SQLAlchemy (see ``setup.py``).\n\n.. code-block:: python\n\n    from sqlalchemy import *\n    from sqlalchemy.engine import create_engine\n    from sqlalchemy.schema import *\n    # Presto\n    engine = create_engine('presto://localhost:8080/hive/default')\n    # Trino\n    engine = create_engine('trino://localhost:8080/hive/default')\n    # Hive\n    engine = create_engine('hive://localhost:10000/default')\n    logs = Table('my_awesome_data', MetaData(bind=engine), autoload=True)\n    print select([func.count('*')], from_obj=logs).scalar()\n\n    # Hive + HTTPS + LDAP or basic Auth\n    engine = create_engine('hive+https://username:password@localhost:10000/')\n    logs = Table('my_awesome_data', MetaData(bind=engine), autoload=True)\n    print select([func.count('*')], from_obj=logs).scalar()\n\nNote: query generation functionality is not exhaustive or fully tested, but there should be no\nproblem with raw SQL.\n\nPassing session configuration\n-----------------------------\n\n.. code-block:: python\n\n    # DB-API\n    hive.connect('localhost', configuration={'hive.exec.reducers.max': '123'})\n    presto.connect('localhost', session_props={'query_max_run_time': '1234m'})\n    trino.connect('localhost',  session_props={'query_max_run_time': '1234m'})\n    # SQLAlchemy\n    create_engine(\n        'presto://user@host:443/hive',\n        connect_args={'protocol': 'https',\n                      'session_props': {'query_max_run_time': '1234m'}}\n    )\n    create_engine(\n        'trino://user@host:443/hive',\n        connect_args={'protocol': 'https',\n                      'session_props': {'query_max_run_time': '1234m'}}\n    )\n    create_engine(\n        'hive://user@host:10000/database',\n        connect_args={'configuration': {'hive.exec.reducers.max': '123'}},\n    )\n    # SQLAlchemy with LDAP\n    create_engine(\n        'hive://user:password@host:10000/database',\n        connect_args={'auth': 'LDAP'},\n    )\n\nRequirements\n============\n\nInstall using\n\n- ``pip install 'pyhive[hive]'`` for the Hive interface and\n- ``pip install 'pyhive[presto]'`` for the Presto interface.\n- ``pip install 'pyhive[trino]'`` for the Trino interface\n\nPyHive works with\n\n- Python 2.7 / Python 3\n- For Presto: Presto install\n- For Trino: Trino install\n- For Hive: `HiveServer2 <https://cwiki.apache.org/confluence/display/Hive/Setting+up+HiveServer2>`_ daemon\n\nChangelog\n=========\nSee https://github.com/dropbox/PyHive/releases.\n\nContributing\n============\n- Please fill out the Dropbox Contributor License Agreement at https://opensource.dropbox.com/cla/ and note this in your pull request.\n- Changes must come with tests, with the exception of trivial things like fixing comments. See .travis.yml for the test environment setup.\n- Notes on project scope:\n\n  - This project is intended to be a minimal Hive/Presto client that does that one thing and nothing else.\n    Features that can be implemented on top of PyHive, such integration with your favorite data analysis library, are likely out of scope.\n  - We prefer having a small number of generic features over a large number of specialized, inflexible features.\n    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.\n\nTesting\n=======\n.. image:: https://travis-ci.org/dropbox/PyHive.svg\n    :target: https://travis-ci.org/dropbox/PyHive\n.. image:: http://codecov.io/github/dropbox/PyHive/coverage.svg?branch=master\n    :target: http://codecov.io/github/dropbox/PyHive?branch=master\n\nRun the following in an environment with Hive/Presto::\n\n    ./scripts/make_test_tables.sh\n    virtualenv --no-site-packages env\n    source env/bin/activate\n    pip install -e .\n    pip install -r dev_requirements.txt\n    py.test\n\nWARNING: This drops/creates tables named ``one_row``, ``one_row_complex``, and ``many_rows``, plus a\ndatabase called ``pyhive_test_database``.\n\nUpdating TCLIService\n====================\n\nThe TCLIService module is autogenerated using a ``TCLIService.thrift`` file. To update it, the\n``generate.py`` file can be used: ``python generate.py <TCLIServiceURL>``. When left blank, the\nversion for Hive 2.3 will be downloaded.\n",
    "bugtrack_url": null,
    "license": "Apache License, Version 2.0",
    "summary": "Python interface to Hive",
    "version": "0.6.3.dev0",
    "project_urls": {
        "Homepage": "https://github.com/dropbox/PyHive"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a6f5b90608dfda2b85902e9df865a4c6fb39235741dcae14216c6aebbc669a20",
                "md5": "71a9365fa1de4c6cc82ca0fb3fdce5c5",
                "sha256": "7c50165fdf62577dea22109bbe0306dfd6550dcb9771e3cf7f2de8becbfc644a"
            },
            "downloads": -1,
            "filename": "PyHive_0.6.3_fix_sqlalchemy2.0-0.6.3.dev0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "71a9365fa1de4c6cc82ca0fb3fdce5c5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 52100,
            "upload_time": "2023-06-19T09:06:32",
            "upload_time_iso_8601": "2023-06-19T09:06:32.428216Z",
            "url": "https://files.pythonhosted.org/packages/a6/f5/b90608dfda2b85902e9df865a4c6fb39235741dcae14216c6aebbc669a20/PyHive_0.6.3_fix_sqlalchemy2.0-0.6.3.dev0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b2c35a6a63937769a6378a095bacb5587ace0728c61c26036b7bfd589e429833",
                "md5": "0d3d60d9d0d3c318a40565409700709e",
                "sha256": "4a20e03cf550e8f00934decbb4aa947caeaabbe5c7daa7b0d4988b04f1110d59"
            },
            "downloads": -1,
            "filename": "PyHive_0.6.3_fix_sqlalchemy2.0-0.6.3.dev0.tar.gz",
            "has_sig": false,
            "md5_digest": "0d3d60d9d0d3c318a40565409700709e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 44585,
            "upload_time": "2023-06-19T09:06:34",
            "upload_time_iso_8601": "2023-06-19T09:06:34.215962Z",
            "url": "https://files.pythonhosted.org/packages/b2/c3/5a6a63937769a6378a095bacb5587ace0728c61c26036b7bfd589e429833/PyHive_0.6.3_fix_sqlalchemy2.0-0.6.3.dev0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-19 09:06:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dropbox",
    "github_project": "PyHive",
    "travis_ci": true,
    "coveralls": true,
    "github_actions": false,
    "lcname": "pyhive-0.6.3-fix-sqlalchemy2.0"
}
        
Elapsed time: 0.10927s