Skip to content

Add cursor configuration to connection args #513

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
6 changes: 4 additions & 2 deletions impala/dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def connect(host='localhost', port=21050, database=None, timeout=None,
ldap_user=None, ldap_password=None, use_kerberos=None,
protocol=None, krb_host=None, use_http_transport=False,
http_path='', auth_cookie_names=None, http_cookie_names=None,
retries=3, jwt=None, user_agent=None):
retries=3, jwt=None, user_agent=None, cursor_configuration=None):
"""Get a connection to HiveServer2 (HS2).

These options are largely compatible with the impala-shell command line
Expand Down Expand Up @@ -103,6 +103,8 @@ def connect(host='localhost', port=21050, database=None, timeout=None,
This is used for auth_mechanism=JWT when using the HTTP transport.
user_agent: A user specified user agent when HTTP transport is used. If none is specified,
'Python/ImpylaHttpClient' is used
cursor_configuration: object that contains configuration options that will be passed to
each cursor, optional
use_ldap : bool, optional
Specify `auth_mechanism='LDAP'` instead.

Expand Down Expand Up @@ -201,7 +203,7 @@ def connect(host='localhost', port=21050, database=None, timeout=None,
http_cookie_names=http_cookie_names,
retries=retries,
jwt=jwt, user_agent=user_agent)
return hs2.HiveServer2Connection(service, default_db=database)
return hs2.HiveServer2Connection(service, default_db=database, cursor_configuration=cursor_configuration)


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

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

def close(self):
"""Close the session and the Thrift transport."""
Expand Down Expand Up @@ -126,7 +127,11 @@ def cursor(self, user=None, configuration=None, convert_types=True,

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

session = self.service.open_session(user, configuration)
session_configuration = {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

The comments about configuration could be updated to reflect that it overrides connection level cursor_configuration

for conf in [self.cursor_configuration, configuration]:
if conf is not None:
session_configuration.update(conf)
session = self.service.open_session(user, session_configuration if session_configuration else None)

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