Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openlineage, postgres: add OpenLineage support for Postgres #31617

Merged
merged 3 commits into from
Jul 26, 2023

Conversation

JDarDagran
Copy link
Contributor

This PR adds OpenLineage support for PostgresOperator.

depends on: #31398

Returns default schema specific to database.
See: :class:`~providers.openlineage.utils.sqlparser.SQLParser`
"""
return self.__schema or "public"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added support for both database and schema.

@JDarDagran JDarDagran force-pushed the aip-53-postgresql branch 3 times, most recently from e9293a4 to c2c3403 Compare July 4, 2023 21:36
@uranusjr
Copy link
Member

uranusjr commented Jul 5, 2023

Need to fix the errors

@JDarDagran
Copy link
Contributor Author

JDarDagran commented Jul 5, 2023

Need to fix the errors

@uranusjr I'm on it. Spotted that PostgresOperator has the capability to connect to Redshift as well so I'm converting to draft for a bit to provide support for that too.

@JDarDagran JDarDagran marked this pull request as draft July 5, 2023 09:36
@pankajkoti pankajkoti removed their request for review July 12, 2023 12:23
@JDarDagran JDarDagran marked this pull request as ready for review July 21, 2023 16:44
@JDarDagran JDarDagran force-pushed the aip-53-postgresql branch 2 times, most recently from b2b130f to 31dbf3d Compare July 24, 2023 09:33
Signed-off-by: Jakub Dardzinski <[email protected]>

Add default port for Postgres connection.

Signed-off-by: Jakub Dardzinski <[email protected]>
@mobuchowski mobuchowski merged commit 6b11381 into apache:main Jul 26, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants