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: fix / add some task attributes in AirflowRunFacet #40725

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions airflow/providers/openlineage/extractors/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ def convert_to_ol_dataset_from_object_storage_uri(uri: str) -> Dataset | None:
def convert_to_ol_dataset_from_table(table: Table) -> Dataset:
from openlineage.client.facet import (
BaseFacet,
DocumentationDatasetFacet,
OwnershipDatasetFacet,
OwnershipDatasetFacetOwners,
SchemaDatasetFacet,
Expand Down Expand Up @@ -231,6 +232,8 @@ def convert_to_ol_dataset_from_table(table: Table) -> Dataset:
for user in table.owners
]
)
if table.description:
facets["documentation"] = DocumentationDatasetFacet(description=table.description)
return Dataset(
namespace=f"{table.cluster}",
name=f"{table.database}.{table.name}",
Expand Down
6 changes: 4 additions & 2 deletions airflow/providers/openlineage/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from packaging.version import Version

from airflow import __version__ as AIRFLOW_VERSION
from airflow.datasets import Dataset
from airflow.exceptions import AirflowProviderDeprecationWarning # TODO: move this maybe to Airflow's logic?
from airflow.models import DAG, BaseOperator, MappedOperator
from airflow.providers.openlineage import conf
Expand Down Expand Up @@ -260,13 +261,14 @@ class TaskInfo(InfoJsonEncodable):
]
casts = {
"operator_class": lambda task: task.task_type,
"operator_class_path": lambda task: get_fully_qualified_class_name(task),
"task_group": lambda task: (
TaskGroupInfo(task.task_group)
if hasattr(task, "task_group") and getattr(task.task_group, "_group_id", None)
else None
),
"inlets": lambda task: [DatasetInfo(inlet) for inlet in task.inlets],
"outlets": lambda task: [DatasetInfo(outlet) for outlet in task.outlets],
"inlets": lambda task: [DatasetInfo(i) for i in task.inlets if isinstance(i, Dataset)],
"outlets": lambda task: [DatasetInfo(o) for o in task.outlets if isinstance(o, Dataset)],
}


Expand Down
3 changes: 3 additions & 0 deletions tests/providers/openlineage/extractors/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import pytest
from openlineage.client.facet import (
DocumentationDatasetFacet,
OwnershipDatasetFacet,
OwnershipDatasetFacetOwners,
SchemaDatasetFacet,
Expand Down Expand Up @@ -94,6 +95,7 @@ def test_convert_to_ol_dataset_from_table_with_columns_and_owners():
User(email="[email protected]", last_name="Smith"),
User(email="[email protected]"),
],
description="test description",
)
expected_facets = {
"schema": SchemaDatasetFacet(
Expand All @@ -118,6 +120,7 @@ def test_convert_to_ol_dataset_from_table_with_columns_and_owners():
OwnershipDatasetFacetOwners(name="user:<[email protected]>", type=""),
]
),
"documentation": DocumentationDatasetFacet(description="test description"),
}
result = ExtractorManager.convert_to_ol_dataset_from_table(table)
assert result.namespace == "c1"
Expand Down