Area: Ingestion
Sub-Area: Streaming
Applies to: OSS + Cloud
Issue
Lineage from Apache Spark or Apache Flink jobs does not show up in DataHub, or you don't know how to set up each integration.
You Might Be Asking
- How do I capture Spark job lineage?
- Can DataHub track Flink jobs?
- How do I add lineage for custom ETL code?
Cause
Spark and Flink use different paths into DataHub.
- Spark uses the DataHub Spark agent. It only runs if you load the agent jar and register its listener. Setting only
spark.datahub.rest.servercaptures nothing. - Flink has no job listener. Flink metadata comes from the
flinkingestion source, which reads from the Flink JobManager REST API.
Solution
1. Capture Spark lineage with the Spark agent
Set all of these Spark properties. The first two are required.
spark.jars.packages io.acryl:acryl-spark-lineage_2.12:<version>
spark.extraListeners datahub.spark.DatahubSparkListener
spark.datahub.rest.server <your DataHub server URL>
spark.datahub.rest.token <your personal access token>
- Use
acryl-spark-lineage_2.13if your Spark build uses Scala 2.13. - The listener class is
datahub.spark.DatahubSparkListener. -
spark.datahub.rest.serverdefaults tohttp://localhost:8080. - On DataHub Cloud, use your tenant URL with
/gms(https://<tenant>.acryl.io/gms) and a personal access token. - Get the current
<version>and setup steps for spark-submit, EMR, notebooks and Databricks from the Spark agent documentation.
Other spark.datahub. options:
-
emitter:rest,kafkaorfile. The default isrest. -
file.filename: the output file for thefileemitter. -
patch.enabled: false when you don't set it. -
coalesce_jobs: controls whether the agent merges stored jobs and emits them when the application ends. With coalescing off, the agent emits each event's metadata right away.
2. Capture Flink metadata with the flink source
Run the flink ingestion source. It is available in current releases. Point it at the JobManager REST API:
source:
type: flink
config:
connection:
rest_api_url: <JobManager REST API URL>
sql_gateway_url: <optional SQL Gateway URL>
include_lineage: true
include_run_history: true
-
connection.rest_api_urlis required. -
connection.sql_gateway_urlis optional. It resolves SQL and Table API table references to platforms. -
include_lineagedefaults to true. It builds source and sink lineage from execution plans. -
include_run_historydefaults to true. It emits DataProcessInstance entities. - Add your usual sink to the recipe, then run it with
datahub ingest -c <file>.
See the Flink source documentation.
3. Emit lineage yourself for custom ETL code
Use a patch to add an upstream edge. A patch adds or updates one edge and leaves the other edges alone.
from datahub.emitter.mce_builder import make_dataset_urn
from datahub.emitter.rest_emitter import DatahubRestEmitter
from datahub.metadata.schema_classes import UpstreamClass
from datahub.specific.dataset import DatasetPatchBuilder
emitter = DatahubRestEmitter("<your DataHub server URL>", token="<your personal access token>")
source_urn = make_dataset_urn("hive", "source_db.source_table")
target_urn = make_dataset_urn("hive", "target_db.target_table")
patch = DatasetPatchBuilder(target_urn).add_upstream_lineage(
UpstreamClass(dataset=source_urn, type="TRANSFORMED")
)
for mcp in patch.build():
emitter.emit(mcp)
- The SDK lineage client's
add_lineage(*, upstream, downstream, ...)also builds aDatasetPatchBuilderfor the downstream dataset. - Avoid
set_upstream_lineages(...). It writes the whole list and replaces all upstream edges. - Connectors with
incremental_lineagefalse re-state their lineage on each run. This is the default for most warehouse sources. dbt defaults it to true, so dbt adds to existing lineage. - If you emit
DataProcessInstanceProperties,name(a string) andcreated(anAuditStampClass, not an integer) are required.
If you must write a whole upstreamLineage aspect, emit_mcp takes one MetadataChangeProposalWrapper. It has no entity_urn, aspect_name or aspect keyword arguments, so those raise TypeError. Patches are safer whenever a connector also writes lineage for the same dataset.
from datahub.emitter.mcp import MetadataChangeProposalWrapper
from datahub.metadata.schema_classes import UpstreamLineageClass
upstream_lineage = UpstreamLineageClass(
upstreams=[UpstreamClass(dataset=source_urn, type="TRANSFORMED")]
)
emitter.emit_mcp(
MetadataChangeProposalWrapper(entityUrn=target_urn, aspect=upstream_lineage)
)
For the full emitter reference, see Python emitter. For lineage how-tos, see SDK lineage tutorial.