Cleanup lineage on pipeline and store procedure removal (#19133)

(cherry picked from commit f9de2b926ad7048032fd5c222d35445b1bdda7da)
This commit is contained in:
Mohit Yadav 2024-12-19 12:39:44 +05:30 committed by mohitdeuex
parent 912ca638c5
commit 077e143315
4 changed files with 29 additions and 5 deletions

View File

@ -1180,10 +1180,7 @@ public interface CollectionDAO {
+ "AND json->>'source' = :source",
connectionType = POSTGRES)
void deleteLineageBySourcePipeline(
@BindUUID("toId") UUID toId,
@Bind("toEntity") String toEntity,
@Bind("source") String source,
@Bind("relation") int relation);
@BindUUID("toId") UUID toId, @Bind("source") String source, @Bind("relation") int relation);
class FromRelationshipMapper implements RowMapper<EntityRelationshipRecord> {
@Override

View File

@ -633,7 +633,7 @@ public class LineageRepository {
.findLineageBySourcePipeline(toId, toEntity, source, Relationship.UPSTREAM.ordinal());
// Finally, delete lineage relationship
dao.relationshipDAO()
.deleteLineageBySourcePipeline(toId, toEntity, source, Relationship.UPSTREAM.ordinal());
.deleteLineageBySourcePipeline(toId, toEntity, Relationship.UPSTREAM.ordinal());
} else {
relations =
dao.relationshipDAO()

View File

@ -42,6 +42,8 @@ import org.openmetadata.schema.type.ChangeDescription;
import org.openmetadata.schema.type.EntityReference;
import org.openmetadata.schema.type.FieldChange;
import org.openmetadata.schema.type.Include;
import org.openmetadata.schema.type.LineageDetails;
import org.openmetadata.schema.type.Relationship;
import org.openmetadata.schema.type.Status;
import org.openmetadata.schema.type.TagLabel;
import org.openmetadata.schema.type.Task;
@ -296,6 +298,18 @@ public class PipelineRepository extends EntityRepository<Pipeline> {
pipeline.withService(service).withTasks(taskWithTagsAndOwners);
}
@Override
protected void cleanup(Pipeline pipeline) {
// When a pipeline is removed , the linege needs to be removed
daoCollection
.relationshipDAO()
.deleteLineageBySourcePipeline(
pipeline.getId(),
LineageDetails.Source.PIPELINE_LINEAGE.value(),
Relationship.UPSTREAM.ordinal());
super.cleanup(pipeline);
}
@Override
public void storeRelationships(Pipeline pipeline) {
addServiceRelationship(pipeline, pipeline.getService());

View File

@ -11,6 +11,7 @@ import org.openmetadata.schema.entity.data.DatabaseSchema;
import org.openmetadata.schema.entity.data.StoredProcedure;
import org.openmetadata.schema.type.EntityReference;
import org.openmetadata.schema.type.Include;
import org.openmetadata.schema.type.LineageDetails;
import org.openmetadata.schema.type.Relationship;
import org.openmetadata.service.Entity;
import org.openmetadata.service.resources.databases.StoredProcedureResource;
@ -69,6 +70,18 @@ public class StoredProcedureRepository extends EntityRepository<StoredProcedure>
Relationship.CONTAINS);
}
@Override
protected void cleanup(StoredProcedure storedProcedure) {
// When a pipeline is removed , the linege needs to be removed
daoCollection
.relationshipDAO()
.deleteLineageBySourcePipeline(
storedProcedure.getId(),
LineageDetails.Source.QUERY_LINEAGE.value(),
Relationship.UPSTREAM.ordinal());
super.cleanup(storedProcedure);
}
@Override
public void setInheritedFields(StoredProcedure storedProcedure, EntityUtil.Fields fields) {
DatabaseSchema schema =