Fix #13906 - Fix add_mlmodel_lineage description field (#13920)

This commit is contained in:
Pere Miquel Brull 2023-11-10 10:46:09 +01:00 committed by GitHub
parent b250cd8808
commit 8891a9a410
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View File

@ -55,11 +55,14 @@ class OMetaMlModelMixin(OMetaLineageMixin):
client: REST
def add_mlmodel_lineage(self, model: MlModel) -> Dict[str, Any]:
def add_mlmodel_lineage(
self, model: MlModel, description: Optional[str] = None
) -> Dict[str, Any]:
"""
Iterates over MlModel's Feature Sources and
add the lineage information.
:param model: MlModel containing EntityReferences
:param description: Lineage description
:return: List of added lineage information
"""
@ -77,8 +80,8 @@ class OMetaMlModelMixin(OMetaLineageMixin):
for entity_ref in refs:
self.add_lineage(
AddLineageRequest(
description="MlModel uses FeatureSource",
edge=EntitiesEdge(
description=description,
fromEntity=entity_ref,
toEntity=self.get_entity_reference(
entity=MlModel, fqn=model.fullyQualifiedName

View File

@ -62,6 +62,7 @@ from metadata.generated.schema.entity.services.mlmodelService import (
from metadata.generated.schema.security.client.openMetadataJWTClientConfig import (
OpenMetadataJWTClientConfig,
)
from metadata.generated.schema.type.entityLineage import EntitiesEdge
from metadata.generated.schema.type.entityReference import EntityReference
from metadata.ingestion.ometa.ometa_api import OpenMetadata
@ -373,6 +374,24 @@ class OMetaModelTest(TestCase):
nodes = {node["id"] for node in lineage["nodes"]}
assert nodes == {str(table1_entity.id.__root__), str(table2_entity.id.__root__)}
# If we delete the lineage, the `add_mlmodel_lineage` will take care of it too
for edge in lineage.get("upstreamEdges") or []:
self.metadata.delete_lineage_edge(
edge=EntitiesEdge(
fromEntity=EntityReference(id=edge["fromEntity"], type="table"),
toEntity=EntityReference(id=edge["toEntity"], type="mlmodel"),
)
)
self.metadata.add_mlmodel_lineage(model=res)
lineage = self.metadata.get_lineage_by_id(
entity=MlModel, entity_id=str(res.id.__root__)
)
nodes = {node["id"] for node in lineage["nodes"]}
assert nodes == {str(table1_entity.id.__root__), str(table2_entity.id.__root__)}
self.metadata.delete(
entity=DatabaseService,
entity_id=service_entity.id,