Taragolis commented on code in PR #38871:
URL: https://github.com/apache/airflow/pull/38871#discussion_r1558040645
##########
airflow/providers/common/sql/hooks/sql.py:
##########
@@ -207,6 +219,24 @@ def get_uri(self) -> str:
conn.schema = self.__schema or conn.schema
return conn.get_uri()
+ def get_sqlalchemy_url(self) -> URL:
+ """
+ Return a Sqlalchemy.engine.URL object from the connection.
+
+ :return: the extracted sqlalchemy.engine.URL object.
+ """
+ conn = self.get_connection(getattr(self, self.conn_name_attr))
+ conn.schema = self.__schema or conn.schema
+ conn.port = conn.port or 5432
Review Comment:
`5432` - Postgres
`3306` - MySQL
`1521` - Oracle DB
`1433` - MS SQL
`5439` - Amazon Redshift
`443` - Snowflake
`1025` - Terradata
`5434`- Vertica
and many others
##########
airflow/providers/common/sql/hooks/sql.py:
##########
@@ -207,6 +219,24 @@ def get_uri(self) -> str:
conn.schema = self.__schema or conn.schema
return conn.get_uri()
+ def get_sqlalchemy_url(self) -> URL:
+ """
+ Return a Sqlalchemy.engine.URL object from the connection.
+
+ :return: the extracted sqlalchemy.engine.URL object.
+ """
+ conn = self.get_connection(getattr(self, self.conn_name_attr))
+ conn.schema = self.__schema or conn.schema
+ conn.port = conn.port or 5432
+ return URL.create(
+ drivername=self.drivername,
+ username=conn.login,
+ password=conn.password,
+ host=conn.host,
+ port=conn.port,
+ database=conn.schema,
+ )
Review Comment:
That is also does not work in all cases. Recent example is AthenaSQLHook
https://github.com/apache/airflow/blob/666127238b727c9ee5dfaa1d65782b9d1ab105ed/airflow/providers/amazon/aws/hooks/athena_sql.py#L142-L155
--
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]