jason810496 commented on code in PR #56298:
URL: https://github.com/apache/airflow/pull/56298#discussion_r2442918510
##########
providers/presto/src/airflow/providers/presto/hooks/presto.py:
##########
@@ -150,6 +150,47 @@ def get_conn(self) -> Connection:
return presto_conn
+ @property
+ def sqlalchemy_url(self) -> URL:
+ """Return a `sqlalchemy.engine.URL` object constructed from the
connection."""
+ conn = self.get_connection(self.get_conn_id())
+ extra = conn.extra_dejson or {}
+
+ if not conn.host:
+ raise ValueError("Presto connection error: 'host' is missing in
the connection.")
+ if not conn.port:
+ raise ValueError("Presto connection error: 'port' is missing in
connection.")
+ if not conn.login:
+ raise ValueError("Presto connection error: 'login' is missing in
Connection")
+
+ # adding only when **kwargs are given by user
+ query = {
+ k: v
+ for k, v in {
+ "schema": conn.schema,
+ "protocol": extra.get("protocol"),
+ "source": extra.get("source"),
+ "catalog": extra.get("catalog"),
+ }.items()
+ if v is not None
+ }
+
+ url_query_params = {k: v for k, v in query.items() if v is not None}
Review Comment:
```suggestion
```
##########
providers/presto/src/airflow/providers/presto/hooks/presto.py:
##########
@@ -150,6 +150,47 @@ def get_conn(self) -> Connection:
return presto_conn
+ @property
+ def sqlalchemy_url(self) -> URL:
+ """Return a `sqlalchemy.engine.URL` object constructed from the
connection."""
+ conn = self.get_connection(self.get_conn_id())
+ extra = conn.extra_dejson or {}
+
+ if not conn.host:
+ raise ValueError("Presto connection error: 'host' is missing in
the connection.")
+ if not conn.port:
+ raise ValueError("Presto connection error: 'port' is missing in
connection.")
+ if not conn.login:
+ raise ValueError("Presto connection error: 'login' is missing in
Connection")
+
+ # adding only when **kwargs are given by user
+ query = {
+ k: v
+ for k, v in {
+ "schema": conn.schema,
+ "protocol": extra.get("protocol"),
+ "source": extra.get("source"),
+ "catalog": extra.get("catalog"),
+ }.items()
+ if v is not None
+ }
+
+ url_query_params = {k: v for k, v in query.items() if v is not None}
+
+ return URL.create(
+ drivername="presto",
+ username=conn.login,
+ password=conn.password or "",
+ host=str(conn.host),
+ port=conn.port,
+ database=extra.get("catalog"),
+ query=url_query_params,
Review Comment:
```suggestion
query=query,
```
##########
providers/presto/src/airflow/providers/presto/hooks/presto.py:
##########
@@ -150,6 +150,47 @@ def get_conn(self) -> Connection:
return presto_conn
+ @property
+ def sqlalchemy_url(self) -> URL:
+ """Return a `sqlalchemy.engine.URL` object constructed from the
connection."""
+ conn = self.get_connection(self.get_conn_id())
+ extra = conn.extra_dejson or {}
+
+ if not conn.host:
+ raise ValueError("Presto connection error: 'host' is missing in
the connection.")
+ if not conn.port:
+ raise ValueError("Presto connection error: 'port' is missing in
connection.")
+ if not conn.login:
+ raise ValueError("Presto connection error: 'login' is missing in
Connection")
Review Comment:
```suggestion
required_attrs = ["host", "login", "port"]
for attr in required_attrs:
if getattr(conn, attr) is None:
raise ValueError(f"Presto connection error: '{attr}' is
missing in the connection.")
```
--
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]