guan404ming commented on code in PR #48917:
URL: https://github.com/apache/airflow/pull/48917#discussion_r2035628225
##########
providers/trino/src/airflow/providers/trino/hooks/trino.py:
##########
@@ -322,3 +323,38 @@ def get_openlineage_database_dialect(self, _):
def get_openlineage_default_schema(self):
"""Return Trino default schema."""
return trino.constants.DEFAULT_SCHEMA
+
+ def get_uri(self) -> str:
+ """Return the Trino URI for the connection."""
+ conn = self.connection
+ uri = "trino://"
+
+ auth_part = ""
+ if conn.login:
+ auth_part = quote_plus(conn.login)
+ if conn.password:
+ auth_part = f"{auth_part}:{quote_plus(conn.password)}"
+ auth_part = f"{auth_part}@"
+
+ host_part = conn.host or "localhost"
+ if conn.port:
+ host_part = f"{host_part}:{conn.port}"
+
+ schema_part = ""
+ if conn.schema:
+ schema_part = f"/{quote_plus(conn.schema)}"
+ extra_schema = conn.extra_dejson.get("schema")
+ if extra_schema:
+ schema_part = f"{schema_part}/{quote_plus(extra_schema)}"
+
+ uri = f"{uri}{auth_part}{host_part}{schema_part}"
+
+ extra = conn.extra_dejson.copy()
+ if "schema" in extra:
+ extra.pop("schema")
+
+ query_params = {k: str(v) for k, v in extra.items() if v is not None}
+ if query_params:
+ uri = f"{uri}?{urlencode(query_params)}"
Review Comment:
I think we'are currently overwritting the `get_uri` here mentioned in
https://github.com/apache/airflow/issues/38195#issue-2189527783, but I'm not
100% sure I'm right though.
https://github.com/apache/airflow/blob/2ab60812a040cb8b760acaf396f625d0d719e4be/airflow/providers/common/sql/hooks/sql.py#L184-L192
however the code you provided did cover the case which `Trino` has, maybe we
could consider to implement the more generic `get_uri` in `DbApiHook`
##########
providers/trino/src/airflow/providers/trino/hooks/trino.py:
##########
@@ -322,3 +323,38 @@ def get_openlineage_database_dialect(self, _):
def get_openlineage_default_schema(self):
"""Return Trino default schema."""
return trino.constants.DEFAULT_SCHEMA
+
+ def get_uri(self) -> str:
+ """Return the Trino URI for the connection."""
+ conn = self.connection
+ uri = "trino://"
+
+ auth_part = ""
+ if conn.login:
+ auth_part = quote_plus(conn.login)
+ if conn.password:
+ auth_part = f"{auth_part}:{quote_plus(conn.password)}"
+ auth_part = f"{auth_part}@"
+
+ host_part = conn.host or "localhost"
+ if conn.port:
+ host_part = f"{host_part}:{conn.port}"
+
+ schema_part = ""
+ if conn.schema:
+ schema_part = f"/{quote_plus(conn.schema)}"
+ extra_schema = conn.extra_dejson.get("schema")
+ if extra_schema:
+ schema_part = f"{schema_part}/{quote_plus(extra_schema)}"
+
+ uri = f"{uri}{auth_part}{host_part}{schema_part}"
+
+ extra = conn.extra_dejson.copy()
+ if "schema" in extra:
+ extra.pop("schema")
+
+ query_params = {k: str(v) for k, v in extra.items() if v is not None}
+ if query_params:
+ uri = f"{uri}?{urlencode(query_params)}"
Review Comment:
I think we'are currently overwriting the `get_uri` here mentioned in
https://github.com/apache/airflow/issues/38195#issue-2189527783, but I'm not
100% sure I'm right though.
https://github.com/apache/airflow/blob/2ab60812a040cb8b760acaf396f625d0d719e4be/airflow/providers/common/sql/hooks/sql.py#L184-L192
however the code you provided did cover the case which `Trino` has, maybe we
could consider to implement the more generic `get_uri` in `DbApiHook`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]