tatiana commented on code in PR #31617:
URL: https://github.com/apache/airflow/pull/31617#discussion_r1219888017
##########
airflow/providers/common/sql/hooks/sql.py:
##########
@@ -516,3 +517,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:
If `self.__schema` is coming from the connection, it will map to the
Postgres `database`, due to the legacy implementation:
https://github.com/apache/airflow/blob/main/airflow/providers/postgres/hooks/postgres.py#L84-L102
Until recently, the Postgres connection didn't allow users to specify the
schema. Psycopg would allow us to do this using:
```
psycopg2.connect(host="localhost",
port="5432",
user="postgres",
password="password",
database="database",
options="-c search_path=dbo,public")
```
https://stackoverflow.com/questions/59298580/how-to-specify-schema-in-psycopg2-connection-method
But until recently, this wasn't exposed.
We could look into allowing users to define the default schema per database
using a Airflow configs, similar to what was done in:
https://astro-sdk-python.readthedocs.io/en/stable/configurations.html#configuring-the-database-default-schema
--
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]