-
Notifications
You must be signed in to change notification settings - Fork 16.5k
Add base OpenLineage provider implementation #29940
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
Merged
+2,806
−284
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,6 +75,7 @@ body: | |
| - neo4j | ||
| - odbc | ||
| - openfaas | ||
| - openlineage | ||
| - opsgenie | ||
| - oracle | ||
| - pagerduty | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| .. Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you under the Apache License, Version 2.0 (the | ||
| "License"); you may not use this file except in compliance | ||
| with the License. You may obtain a copy of the License at | ||
|
|
||
| .. http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| .. Unless required by applicable law or agreed to in writing, | ||
| software distributed under the License is distributed on an | ||
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| KIND, either express or implied. See the License for the | ||
| specific language governing permissions and limitations | ||
| under the License. | ||
|
|
||
|
|
||
| Changelog | ||
| --------- | ||
|
|
||
| 1.0.0 | ||
| ..... | ||
|
|
||
| Initial version of the provider. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| from __future__ import annotations | ||
|
|
||
| __all__ = ["version"] | ||
|
|
||
| try: | ||
| import importlib_metadata as metadata | ||
| except ImportError: | ||
| from importlib import metadata # type: ignore[no-redef] | ||
|
|
||
| try: | ||
| version = metadata.version("apache-airflow-providers-openlineage") | ||
| except metadata.PackageNotFoundError: | ||
| import logging | ||
|
|
||
| log = logging.getLogger(__name__) | ||
| log.warning("Package metadata could not be found. Overriding it with version found in setup.py") | ||
| # TODO: What should be a proper fallback? | ||
| # If hardcoded version from provider version | ||
| # there's no point to use metadata above | ||
| version = "1.0.0.dev" | ||
|
|
||
| del metadata |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from airflow.providers.openlineage.extractors.base import BaseExtractor, OperatorLineage | ||
| from airflow.providers.openlineage.extractors.manager import ExtractorManager | ||
|
|
||
| __all__ = ["BaseExtractor", "OperatorLineage", "ExtractorManager"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from abc import ABC, abstractmethod | ||
|
|
||
| from attrs import Factory, define | ||
|
|
||
| from airflow.utils.log.logging_mixin import LoggingMixin | ||
| from openlineage.client.facet import BaseFacet | ||
| from openlineage.client.run import Dataset | ||
|
|
||
|
|
||
| @define | ||
| class OperatorLineage: | ||
| """Structure returned from lineage extraction.""" | ||
|
|
||
| inputs: list[Dataset] = Factory(list) | ||
| outputs: list[Dataset] = Factory(list) | ||
| run_facets: dict[str, BaseFacet] = Factory(dict) | ||
| job_facets: dict[str, BaseFacet] = Factory(dict) | ||
|
|
||
|
|
||
| class BaseExtractor(ABC, LoggingMixin): | ||
| """ | ||
| Abstract base extractor class. | ||
|
|
||
| This is used mostly to maintain support for custom extractors. | ||
| """ | ||
|
|
||
| _allowed_query_params: list[str] = [] | ||
|
|
||
| def __init__(self, operator): # type: ignore | ||
| super().__init__() | ||
| self.operator = operator | ||
|
|
||
| @classmethod | ||
| @abstractmethod | ||
| def get_operator_classnames(cls) -> list[str]: | ||
| """ | ||
| Implement this method returning list of operators that extractor works for. | ||
mobuchowski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| There are operators which work very similarly and one extractor can cover both. | ||
| """ | ||
| raise NotImplementedError() | ||
|
|
||
| def validate(self): | ||
| assert self.operator.task_type in self.get_operator_classnames() | ||
|
|
||
| @abstractmethod | ||
| def extract(self) -> OperatorLineage | None: | ||
| pass | ||
|
|
||
| def extract_on_complete(self, task_instance) -> OperatorLineage | None: | ||
| return self.extract() | ||
|
|
||
|
|
||
| class DefaultExtractor(BaseExtractor): | ||
| """Extractor that uses `get_openlineage_facets_on_start/complete/failure` methods.""" | ||
|
|
||
| @classmethod | ||
| def get_operator_classnames(cls) -> list[str]: | ||
| """ | ||
| Default extractor is chosen not on the classname basis, but | ||
| by existence of get_openlineage_facets method on operator | ||
| """ | ||
| return [] | ||
|
|
||
| def extract(self) -> OperatorLineage | None: | ||
| try: | ||
| return self._get_openlineage_facets(self.operator.get_openlineage_facets_on_start) # type: ignore | ||
| except AttributeError: | ||
| return None | ||
|
|
||
| def extract_on_complete(self, task_instance) -> OperatorLineage | None: | ||
| on_complete = getattr(self.operator, "get_openlineage_facets_on_complete", None) | ||
| if on_complete and callable(on_complete): | ||
| return self._get_openlineage_facets(on_complete, task_instance) | ||
| return self.extract() | ||
|
|
||
| def _get_openlineage_facets(self, get_facets_method, *args) -> OperatorLineage | None: | ||
| facets: OperatorLineage = get_facets_method(*args) | ||
| return OperatorLineage( | ||
| inputs=facets.inputs, | ||
| outputs=facets.outputs, | ||
| run_facets=facets.run_facets, | ||
| job_facets=facets.job_facets, | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.