From 9b9c848a8b29551b880b90d1973e11ea5a95bce2 Mon Sep 17 00:00:00 2001 From: Michiel De Smet Date: Fri, 16 Sep 2022 15:22:32 +0200 Subject: [PATCH] Implement roles support in sqlalchemy --- README.md | 4 +++- trino/sqlalchemy/dialect.py | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 19dda261..d24d714a 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,7 @@ engine = create_engine( "session_properties": {'query_max_run_time': '1d'}, "client_tags": ["tag1", "tag2"], "experimental_python_types": True, + "roles": {"catalog1": "role1"}, } ) @@ -108,7 +109,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"}' ) ``` diff --git a/trino/sqlalchemy/dialect.py b/trino/sqlalchemy/dialect.py index e967cb6b..c5bccf37 100644 --- a/trino/sqlalchemy/dialect.py +++ b/trino/sqlalchemy/dialect.py @@ -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]]: