-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docs) add fine-grained lineage section to dataset doc. Include e…
…xamples in the lineage doc. Accordingly segregate ingestion examples of fine-grained lineage of dataset and datajob.
- Loading branch information
Showing
4 changed files
with
329 additions
and
45 deletions.
There are no files selected for viewing
This file contains 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 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
84 changes: 84 additions & 0 deletions
84
metadata-ingestion/examples/library/lineage_emitter_dataset_finegrained.py
This file contains 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,84 @@ | ||
import datahub.emitter.mce_builder as builder | ||
import json | ||
|
||
from datahub.emitter.mcp import MetadataChangeProposalWrapper | ||
from datahub.emitter.rest_emitter import DatahubRestEmitter | ||
from datahub.metadata.com.linkedin.pegasus2avro.dataset import ( | ||
DatasetLineageType, | ||
FineGrainedLineage, | ||
FineGrainedLineageDownstreamType, | ||
FineGrainedLineageUpstreamType, | ||
Upstream, | ||
UpstreamLineage | ||
) | ||
from datahub.metadata.schema_classes import ChangeTypeClass, DataJobInputOutputClass | ||
|
||
def datasetUrn(tbl): | ||
return builder.make_dataset_urn("postgres", tbl) | ||
|
||
def fldUrn(tbl, fld): | ||
return builder.make_schema_field_urn(datasetUrn(tbl), fld); | ||
|
||
# Lineage of fields in a dataset | ||
# c1 <-- unknownFunc(bar2.c1, bar4.c1) | ||
# c2 <-- myfunc(bar3.c2) | ||
# {c3,c4} <-- unknownFunc(bar2.c2, bar2.c3, bar3.c1) | ||
# c5 <-- unknownFunc(bar3) | ||
# {c6,c7} <-- unknownFunc(bar4) | ||
|
||
# note that the semantic of the "transformOperation" value is contextual. | ||
# In above example, it is regarded as some kind of UDF; but it could also be an expression etc. | ||
|
||
fineGrainedLineages=[ | ||
FineGrainedLineage( | ||
upstreamType=FineGrainedLineageUpstreamType.FIELD_SET, | ||
upstreams=[fldUrn("bar2", "c1"), fldUrn("bar4", "c1")], | ||
downstreamType=FineGrainedLineageDownstreamType.FIELD, | ||
downstreams=[fldUrn("bar", "c1")]), | ||
|
||
FineGrainedLineage( | ||
upstreamType=FineGrainedLineageUpstreamType.FIELD_SET, | ||
upstreams=[fldUrn("bar3","c2")], | ||
downstreamType=FineGrainedLineageDownstreamType.FIELD, | ||
downstreams=[fldUrn("bar", "c2")], | ||
confidenceScore = 0.8, transformOperation="myfunc"), | ||
|
||
FineGrainedLineage( | ||
upstreamType=FineGrainedLineageUpstreamType.FIELD_SET, | ||
upstreams=[fldUrn("bar2","c2"), fldUrn("bar2","c3"), fldUrn("bar3","c1")], | ||
downstreamType=FineGrainedLineageDownstreamType.FIELD_SET, | ||
downstreams=[fldUrn("bar", "c3"), fldUrn("bar", "c4")], | ||
confidenceScore = 0.7), | ||
|
||
FineGrainedLineage( | ||
upstreamType=FineGrainedLineageUpstreamType.DATASET, | ||
upstreams=[datasetUrn("bar3")], | ||
downstreamType=FineGrainedLineageDownstreamType.FIELD, | ||
downstreams=[fldUrn("bar", "c5")]), | ||
|
||
FineGrainedLineage( | ||
upstreamType=FineGrainedLineageUpstreamType.DATASET, | ||
upstreams=[datasetUrn("bar4")], | ||
downstreamType=FineGrainedLineageDownstreamType.FIELD_SET, | ||
downstreams=[fldUrn("bar", "c6"), fldUrn("bar", "c7")]) | ||
] | ||
|
||
|
||
# this is just to check if any conflicts with existing Upstream, particularly the DownstreamOf relationship | ||
upstream = Upstream(dataset=datasetUrn("bar2"), type=DatasetLineageType.TRANSFORMED) | ||
|
||
fieldLineages = UpstreamLineage(upstreams=[upstream], fineGrainedLineages=fineGrainedLineages) | ||
|
||
lineageMcp = MetadataChangeProposalWrapper( | ||
entityType="dataset", | ||
changeType=ChangeTypeClass.UPSERT, | ||
entityUrn=datasetUrn("bar"), | ||
aspectName="upstreamLineage", | ||
aspect=fieldLineages | ||
) | ||
|
||
# Create an emitter to the GMS REST API. | ||
emitter = DatahubRestEmitter("http://localhost:8080") | ||
|
||
# Emit metadata! | ||
emitter.emit_mcp(lineageMcp) |
Oops, something went wrong.