Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work-arround for automatically pass a port number of 10000 #7

Open
alex-ber opened this issue Jan 20, 2021 · 0 comments
Open

Work-arround for automatically pass a port number of 10000 #7

alex-ber opened this issue Jan 20, 2021 · 0 comments

Comments

@alex-ber
Copy link

alex-ber commented Jan 20, 2021

First, thank you very much for you effort.
I've found it here dropbox/PyHive#32

I'm proposing changing documentation for caveat, beside editing hive.py the user can write the following:

from sqlalchemy import create_engine
import puretransport

from pyhive.sqlalchemy_hive import HiveDialect as _HiveDialect
class _HiveFixedDialect(object):

    def create_connect_args(self, url):
        kwargs = {
            'host': url.host,
            'port': url.port,
            #'port': url.port or 10000,
            'username': url.username,
            'password': url.password,
            'database': url.database or 'default',
        }
        kwargs.update(url.query)
        return [], kwargs

_HiveDialect.create_connect_args = _HiveFixedDialect.create_connect_args


transport = puretransport.transport_factory(host='host',
                                            port=10000,
                                            username='username',
                                            password='secret')

# connection string pattern hive://username@/database_name
engine = create_engine('hive://username@/default',
                       connect_args={'thrift_transport': transport})
result = engine.execute("select * from table limit 1")

Note the line _HiveDialect.create_connect_args = _HiveFixedDialect.create_connect_args. This line effectively replaces create_connect_args() function that inserts default 10000 port to our version that didn't.

Note: you can use also 'hive://' as connection string, if you want to connect to default database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant