tatiana commented on code in PR #31398:
URL: https://github.com/apache/airflow/pull/31398#discussion_r1221541144
##########
airflow/providers/common/sql/hooks/sql.py:
##########
@@ -515,3 +516,40 @@ def test_connection(self):
message = str(e)
return status, message
+
+ def get_database_info(self, connection):
+ from airflow.providers.openlineage.sqlparser import DatabaseInfo
+
+ return DatabaseInfo(
+ scheme=self.get_database_dialect(connection),
authority=self._get_authority(connection)
+ )
+
+ def get_database_dialect(self, connection):
+ """Method used for SQL parsing. Naively tries to use Connection's
conn_type"""
+ return connection.conn_type
Review Comment:
Generic should be the default and we should define it at the top of the
module
##########
airflow/providers/common/sql/hooks/sql.py:
##########
@@ -515,3 +516,40 @@ def test_connection(self):
message = str(e)
return status, message
+
+ def get_database_info(self, connection):
Review Comment:
To be renamed get_database_info -> get_openlineage_database_info
This method should be ` :meta private:`
https://github.com/apache/airflow/blob/b7796895cb41d8e5e79e6d8eee150b11d8c302a7/airflow/utils/mixins.py#L57-L63
##########
airflow/providers/common/sql/hooks/sql.py:
##########
@@ -515,3 +516,40 @@ def test_connection(self):
message = str(e)
return status, message
+
+ def get_database_info(self, connection):
+ from airflow.providers.openlineage.sqlparser import DatabaseInfo
+
+ return DatabaseInfo(
+ scheme=self.get_database_dialect(connection),
authority=self._get_authority(connection)
+ )
+
+ def get_database_dialect(self, connection):
+ """Method used for SQL parsing. Naively tries to use Connection's
conn_type"""
+ return connection.conn_type
+
+ def _get_authority(self, connection):
+ """Returns authority part (without user info) of OpenLineage namespace
URI."""
+ if connection.port and connection.host:
+ authority = f"{connection.host}:{connection.port}"
+ else:
+ parsed = urlparse(connection.get_uri())
+ authority = f"{parsed.hostname}:{parsed.port}"
+ return authority
+
+ def get_default_schema(self):
+ """
+ Returns default schema specific to database.
+ See: :class:`~providers.openlineage.utils.sqlparser.SQLParser`
+ """
+ return self.__schema or "public"
Review Comment:
In the case of Postgres, `self.__schema` will return the `database` and not
the schema.
We need to find a way of allowing users to override this.
--
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]