Skip to content
This repository has been archived by the owner on May 5, 2022. It is now read-only.

Commit

Permalink
Merge pull request #25 from shawnzhu/issue-24
Browse files Browse the repository at this point in the history
Support connection parameter sessionUser
  • Loading branch information
dungdm93 authored Sep 6, 2021
2 parents 8045f49 + 68e6f58 commit 5aea362
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sqlalchemy_trino/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def create_connect_args(self, url: URL) -> Tuple[List[Any], Dict[str, Any]]:
raise ValueError(f'Unexpected database format {url.database}')

username = kwargs.pop('username', 'anonymous')
kwargs['user'] = username
session_user = kwargs.pop('sessionUser', username)
kwargs['user'] = session_user

password = kwargs.pop('password', None)
if password:
Expand Down
21 changes: 21 additions & 0 deletions tests/test_dialect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from sqlalchemy.engine import url
from sqlalchemy_trino.dialect import TrinoDialect


def test_trino_connection_string_user():
dialect = TrinoDialect()
username = 'test-user'
u = url.make_url(f'trino://{username}@host')
_, cparams = dialect.create_connect_args(u)

assert cparams['user'] == username


def test_trino_connection_string_session_user():
dialect = TrinoDialect()
username = 'test-user'
session_user = 'sess-user'
u = url.make_url(f'trino://{username}@host/?sessionUser={session_user}')
_, cparams = dialect.create_connect_args(u)

assert cparams['user'] == session_user

0 comments on commit 5aea362

Please sign in to comment.