pure-transport
pure-transport copied to clipboard
Work-arround for automatically pass a port number of 10000
First, thank you very much for you effort. I've found it here https://github.com/dropbox/PyHive/issues/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.