Skip to content

Commit

Permalink
Implement roles support in sqlalchemy
Browse files Browse the repository at this point in the history
  • Loading branch information
mdesmet committed Oct 3, 2022
1 parent de433c7 commit ce5c351
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ engine = create_engine(
"session_properties": {'query_max_run_time': '1d'},
"client_tags": ["tag1", "tag2"],
"experimental_python_types": True,
"roles": {"catalog1": "role1"},
}
)

Expand All @@ -115,7 +116,8 @@ engine = create_engine(
'trino://user@localhost:8080/system?'
'session_properties={"query_max_run_time": "1d"}'
'&client_tags=["tag1", "tag2"]'
'&experimental_python_types=true',
'&experimental_python_types=true'
'&roles={"catalog1": "role1"}'
)
```

Expand Down
10 changes: 10 additions & 0 deletions tests/unit/sqlalchemy/test_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ def setup(self):
experimental_python_types=True,
),
),
(
make_url('trino://user@localhost:8080?roles={"hive":"finance","system":"analyst"}'),
list(),
dict(host="localhost",
port=8080,
catalog="system",
user="user",
roles={"hive": "finance", "system": "analyst"},
source="trino-sqlalchemy"),
),
],
)
def test_create_connect_args(self, url: URL, expected_args: List[Any], expected_kwargs: Dict[str, Any]):
Expand Down
3 changes: 3 additions & 0 deletions trino/sqlalchemy/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ def create_connect_args(self, url: URL) -> Tuple[Sequence[Any], Mapping[str, Any
if "experimental_python_types" in url.query:
kwargs["experimental_python_types"] = json.loads(url.query["experimental_python_types"])

if "roles" in url.query:
kwargs["roles"] = json.loads(url.query["roles"])

return args, kwargs

def get_columns(self, connection: Connection, table_name: str, schema: str = None, **kw) -> List[Dict[str, Any]]:
Expand Down

0 comments on commit ce5c351

Please sign in to comment.