Skip to content

Commit 9e76fb3

Browse files
mdesmethashhar
authored andcommitted
Implement roles support in sqlalchemy
1 parent 61c0f4a commit 9e76fb3

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ engine = create_engine(
107107
"session_properties": {'query_max_run_time': '1d'},
108108
"client_tags": ["tag1", "tag2"],
109109
"experimental_python_types": True,
110+
"roles": {"catalog1": "role1"},
110111
}
111112
)
112113

@@ -115,7 +116,8 @@ engine = create_engine(
115116
'trino://user@localhost:8080/system?'
116117
'session_properties={"query_max_run_time": "1d"}'
117118
'&client_tags=["tag1", "tag2"]'
118-
'&experimental_python_types=true',
119+
'&experimental_python_types=true'
120+
'&roles={"catalog1": "role1"}'
119121
)
120122
```
121123

tests/unit/sqlalchemy/test_dialect.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ def setup(self):
6363
experimental_python_types=True,
6464
),
6565
),
66+
(
67+
make_url('trino://user@localhost:8080?roles={"hive":"finance","system":"analyst"}'),
68+
list(),
69+
dict(host="localhost",
70+
port=8080,
71+
catalog="system",
72+
user="user",
73+
roles={"hive": "finance", "system": "analyst"},
74+
source="trino-sqlalchemy"),
75+
),
6676
],
6777
)
6878
def test_create_connect_args(self, url: URL, expected_args: List[Any], expected_kwargs: Dict[str, Any]):

trino/sqlalchemy/dialect.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ def create_connect_args(self, url: URL) -> Tuple[Sequence[Any], Mapping[str, Any
124124
if "experimental_python_types" in url.query:
125125
kwargs["experimental_python_types"] = json.loads(url.query["experimental_python_types"])
126126

127+
if "roles" in url.query:
128+
kwargs["roles"] = json.loads(url.query["roles"])
129+
127130
return args, kwargs
128131

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

0 commit comments

Comments
 (0)