Skip to content

Commit d8bff52

Browse files
added passing client_tags option to Trino plugin (#7633)
* added cleint_tags added the option to pass client tags to trino clusters source * removed redundant checks * removed redundant test and fixed if condition --------- Co-authored-by: Tsuneo Yoshioka <yoshiokatsuneo@gmail.com>
1 parent a81f777 commit d8bff52

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

redash/query_runner/trino.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def configuration_schema(cls):
5959
"username": {"type": "string"},
6060
"password": {"type": "string"},
6161
"source": {"type": "string", "default": "redash"},
62+
"client_tags": {"type": "string", "title": "Client tags (comma separated)"},
6263
"catalog": {"type": "string"},
6364
"schema": {"type": "string"},
6465
"impersonation": {"type": "boolean", "default": False},
@@ -76,13 +77,15 @@ def configuration_schema(cls):
7677
"username",
7778
"password",
7879
"source",
80+
"client_tags",
7981
"catalog",
8082
"schema",
8183
"impersonation",
8284
],
8385
"required": ["host", "username"],
8486
"secret": ["password"],
8587
"extra_options": [
88+
"client_tags",
8689
"impersonation",
8790
"impersonationField",
8891
],
@@ -161,6 +164,13 @@ def _get_trino_user(self, user):
161164

162165
return default_user
163166

167+
def _get_client_tags(self):
168+
client_tags = self.configuration.get("client_tags")
169+
if not client_tags:
170+
return None
171+
tags = [tag.strip() for tag in client_tags.split(",") if tag.strip()]
172+
return tags or None
173+
164174
def run_query(self, query, user):
165175
if self.configuration.get("password"):
166176
auth = trino.auth.BasicAuthentication(
@@ -177,6 +187,7 @@ def run_query(self, query, user):
177187
catalog=self.configuration.get("catalog", ""),
178188
schema=self.configuration.get("schema", ""),
179189
user=self._get_trino_user(user),
190+
client_tags=self._get_client_tags(),
180191
auth=auth,
181192
)
182193

tests/query_runner/test_trino.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,11 @@ def test__get_catalogs(self, mock_run_query):
5858
catalogs = runner._get_catalogs()
5959
expected_catalogs = [TestTrino.catalog_name]
6060
self.assertEqual(catalogs, expected_catalogs)
61+
62+
def test_get_client_tags_parses_comma_separated_values(self):
63+
runner = Trino({"client_tags": "finance, redash , ,analytics"})
64+
self.assertEqual(runner._get_client_tags(), ["finance", "redash", "analytics"])
65+
66+
def test_get_client_tags_returns_none_when_empty(self):
67+
runner = Trino({"client_tags": " , , "})
68+
self.assertIsNone(runner._get_client_tags())

0 commit comments

Comments
 (0)