Area: Ingestion
Sub-Area: Lineage Management
Applies to: OSS + Cloud
Issue
Old lineage edges still show in DataHub after the upstream tables or pipelines changed. The lineage graph shows connections that no longer exist.
You Might Be Asking
- Why do I still see old lineage connections?
- Does stateful ingestion remove stale lineage edges?
- Did a release fix stale lineage edge removal?
- How do I remove stale lineage?
Cause
Whether an old edge disappears depends on how the source emits lineage. The setting is incremental_lineage (default false).
- When
incremental_lineageisfalse, the source emits the full lineage of each downstream entity that it finds lineage for in that run. This replaces the old edges of that entity. If the source finds no lineage for an entity in a run, it emits nothing for that entity. The old edges of that entity stay. - When
incremental_lineageistrue, the source emits lineage as incremental to the lineage already in DataHub. The Lineage Feature Guide warns that old edges are not removed in this mode. - dbt defaults
incremental_lineagetotrue. In dbt, the setting applies only to lineage on entities that are not dbt entities. The dbt documentation says to enableincremental_lineagein the warehouse source also.
Two sources can emit lineage for the same warehouse table. If the incremental_lineage values of the two sources differ, one source can replace the edges that the other source emitted.
Stateful ingestion with remove_stale_metadata (default true) soft deletes entities that were in the last successful run but are missing from the current run. Use it when the stale upstream entity itself is gone from the source.
Stateful ingestion does not remove individual lineage edges. The setting remove_stale_metadata soft deletes whole entities. It sets the status of each entity to removed. It never removes a single edge between two entities that still exist. When DataHub soft deletes an entity, the edges to it stop showing in the graph. The edges stay in DataHub. No DataHub release, including v0.3.12, added lineage edge removal to stateful ingestion. Stateful ingestion only soft deletes whole entities.
Lineage that you added by hand can be overwritten by lineage from a source. The lineage guide warns about this overwrite between manual and programmatic lineage.
Solution
- Check
incremental_lineagein your recipe. Use the same value in the dbt source and in the warehouse source that share the tables. Then re-run ingestion. - To remove one stale edge now, use a patch.
remove_upstream_lineageremoves a single upstream edge from theupstreamslist of the dataset and leaves the other upstream edges alone. Do not useset_upstream_lineagesfor this, because it replaces all upstream edges.
from datahub.emitter.mce_builder import make_dataset_urn
from datahub.ingestion.graph.client import DataHubGraph
from datahub.ingestion.graph.config import DatahubClientConfig
from datahub.specific.dataset import DatasetPatchBuilder
# OSS: http://localhost:8080. Cloud: https://<tenant>.acryl.io/gms
graph = DataHubGraph(DatahubClientConfig(server="http://localhost:8080", token="<token>"))
downstream = make_dataset_urn(platform="snowflake", name="db.schema.downstream_table")
stale_upstream = make_dataset_urn(platform="snowflake", name="db.schema.old_upstream_table")
patch = DatasetPatchBuilder(downstream).remove_upstream_lineage(stale_upstream)
for mcp in patch.build():
graph.emit(mcp)
Copy the exact dataset URNs from DataHub, because the case rules differ by source. See Python emitter and SDK.
remove_upstream_lineage does not change the column level lineage. If column level edges from the stale upstream stay, use remove_fine_grained_lineage to remove them.
- If the upstream entity no longer exists in the source, enable stateful ingestion so DataHub soft deletes it on the next run:
source:
type: <your-source>
config:
# Your source config
stateful_ingestion:
enabled: true
remove_stale_metadata: true
fail_safe_threshold (default 75.0, a value from 0 to 100) is a percentage. It counts the entities from the previous run that are missing from the current run. When that percentage is above the threshold, DataHub skips the soft deletes and the state commit. See Stateful Ingestion.
Soft delete hides entities. It is not a hard delete. A soft-deleted asset comes back if a source emits it again. See Deleting metadata.