Repository navigation
Make OpenLineage SQL schema lookup configurable - #74776
prabhnoor0212 wants to merge 1 commit into
Conversation
Allow deployments to avoid external database metadata lookups during SQL lineage extraction when those lookups are slow or unreliable.
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
|
| return True | ||
| from airflow.providers.openlineage import conf | ||
|
|
||
| return conf.sql_use_external_connection() |
There was a problem hiding this comment.
Changing should_use_external_connection() does not cover all SQL lineage extraction paths. For example, MySQLToGCSOperator calls get_openlineage_facets_with_sql() through common.compat. With a current OpenLineage provider, that resolves to the implementation in openlineage/sqlparser.py, which defaults to use_connection=True and never checks should_use_external_connection().
The check in common.compat only runs in its fallback implementation for older OpenLineage versions. Consequently, MySQLToGCSOperator can still query information_schema when sql_use_external_connection=False.
Please make the shared helper in openlineage/sqlparser.py honor the setting too, while preserving use_connection=False when explicitly passed by a caller.
| @@ -321,7 +321,7 @@ def get_openlineage_facets_on_start(self) -> OperatorLineage | None: | |||
| hook=hook, | |||
| database_info=database_info, | |||
| database=self.database, | |||
| sqlalchemy_engine=hook.get_sqlalchemy_engine(), | |||
| sqlalchemy_engine=hook.get_sqlalchemy_engine() if use_external_connection else None, | |||
There was a problem hiding this comment.
When the setting is false and the operator uses PostgresHook or MsSqlHook, extraction still calls get_openlineage_default_schema() before reaching this guard. Those implementations execute SELECT CURRENT_SCHEMA; and SELECT SCHEMA_NAME();, respectively, opening an external database connection. A slow or unavailable database can therefore still block extraction or raise before table-only lineage is generated. The disabled path also needs to avoid database-backed default-schema discovery or provide an offline fallback.
Allow SQL OpenLineage extraction to skip external database schema lookups when they are slow or unreliable. When disabled, the SQLAlchemy engine is not created, while connection details remain available for database namespace and dialect identification.
This preserves table-level lineage parsing while allowing schema facets to be less complete.
Validation completed:
prek run --from-ref main --stage pre-commitpassed with Python 3.11git diff --checkpassedWas generative AI tooling used to co-author this PR?
Generated-by: OpenAI ChatGPT following the guidelines at https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions