GitHub user betodealmeida edited a comment on the discussion: Unable to pass
http headers to Trino
Ah, I see... that sounds like a very specific feature it would be hard to
justify adding to the left panel.
I'm trying to think of workarounds. We have the `DB_CONNECTION_MUTATOR`, which
could be used to modify the connection string for each request, but it doesn't
have access to the SQL — otherwise users could add the client tags as comment
in their query. And we have the `SQL_QUERY_MUTATOR`, which could extract the
client tags from the comment, but has no way of modifying the connection string.
There's a hacky way which might work. You can create a `DB_CONNECTION_MUTATOR`
that inspects the stack, finding the SQL that's being executed and extract
client tags from it. Your users would run a query like this:
```sql
-- client-tags: passwd=1234556,adhoc,label=adhoc
SELECT * FROM t;
```
And your connection mutator in `superset_config.py` would look like this
(untested, but the technique should work):
```python
import inspect
def DB_CONNECTION_MUTATOR(
uri: URL,
params: dict[str, Any],
username: str,
security_manager: SupersetSecurityManager,
source: str,
) -> tuple[URL, dict[str, Any]:
for level in inspect.stack():
if level.function == "get_df": # running in explore
sql = level.frame.f_locals["sql"]
break
if level.function == "execute_sql_statements": # running in SQL Lab
sql = level.frame.f_locals["blocks"][0] # alternatively, check
every block
break
else:
return URL, params
pattern = r"--\s*client-tags:\s*(.*)"
match = re.search(pattern, sql, re.IGNORECASE)
if match:
tag_string = match.group(1)
tags = [kv.split("=") if "=" in kv else [kv, None] for kv in
tag_string.split(",")]
client_tags = {k: v for k, v in tags}
connect_args = params.setdefault("connect_args", {})
connect_args["client_tags"] = client_tags
return URL, params
```
GitHub link:
https://github.com/apache/superset/discussions/33695#discussioncomment-13382744
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]