Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions impala/dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def connect(host='localhost', port=21050, database=None, timeout=None,
use_ssl=False, ca_cert=None, auth_mechanism='NOSASL', user=None,
password=None, kerberos_service_name='impala', use_ldap=None,
ldap_user=None, ldap_password=None, use_kerberos=None,
protocol=None):
protocol=None,username=None):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: space after comma to be consistent with surrounding code and PEP8

"""Get a connection to HiveServer2 (HS2).

These options are largely compatible with the impala-shell command line
Expand Down Expand Up @@ -145,7 +145,7 @@ def connect(host='localhost', port=21050, database=None, timeout=None,
ca_cert=ca_cert, user=user, password=password,
kerberos_service_name=kerberos_service_name,
auth_mechanism=auth_mechanism)
return hs2.HiveServer2Connection(service, default_db=database)
return hs2.HiveServer2Connection(service, default_db=database, impersonate=username)


class _DBAPITypeObject(object):
Expand Down
12 changes: 10 additions & 2 deletions impala/hiveserver2.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ class HiveServer2Connection(Connection):
# HiveServer2Connection objects are associated with a TCLIService.Client
# thrift service
# it's instantiated with an alive TCLIService.Client

def __init__(self, service, default_db=None):
impersonate=None

def __init__(self, service, default_db=None, impersonate=None):
log.debug('HiveServer2Connection(service=%s, default_db=%s)', service,
default_db)
self.service = service
self.default_db = default_db
self.impersonate=impersonate

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: spaces around = to be consistent with surrounding code and PEP8


def close(self):
"""Close the session and the Thrift transport."""
Expand Down Expand Up @@ -122,6 +124,12 @@ def cursor(self, user=None, configuration=None, convert_types=True,

log.debug('.cursor(): getting new session_handle')

if self.impersonate != None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log.debug('Impersonating user %s' % self.impersonate)
configuration = {
'impala.doas.user': self.impersonate
}

session = self.service.open_session(user, configuration)

log.debug('HiveServer2Cursor(service=%s, session_handle=%s, '
Expand Down