📊 Data Engineering

Data Lineage

Data Lineage

Tracking data flow. The path from the source to the final result.

Detailed Explanation

Data lineage is a technology that tracks the creation, movement, and transformation of data to visualize the flow from the original source to the final result. It makes it possible to transparently see where data came from, how it was transformed, and where it went.

It is an essential capability for data governance, regulatory compliance (GDPR, SOX, HIPAA), impact analysis, and debugging. When a schema change or data quality issue occurs, it lets you immediately identify which downstream systems are affected, greatly shortening incident response time.

OpenLineage has become established as the industry-standard protocol, and major data tools such as Airflow, Spark, and dbt automatically emit OpenLineage events. Platforms such as DataHub, Marquez, and Apache Atlas collect and visualize lineage graphs.

Column-Level Lineage tracks even which transformations an individual field went through to be created. Through SQL parsing, it automatically extracts mapping relationships between fields in SELECT, JOIN, and GROUP BY operations.

Code Example

Python (OpenLineage)
# OpenLineage 기반 데이터 리니지 추적
from openlineage.client import OpenLineageClient
from openlineage.client.run import (
    RunEvent, RunState, Run, Job,
    InputDataset, OutputDataset
)
from openlineage.client.facet import (
    SqlJobFacet, SchemaDatasetFacet, SchemaField,
    ColumnLineageDatasetFacet
)
import uuid
from datetime import datetime

# OpenLineage 클라이언트 초기화
client = OpenLineageClient(url="http://marquez:5000")
namespace = "data_platform"

# Job과 Run 정의
job = Job(namespace=namespace, name="daily_customer_aggregation")
run = Run(runId=str(uuid.uuid4()))

# 리니지 이벤트 발행: 작업 시작
start_event = RunEvent(
    eventType=RunState.START,
    eventTime=datetime.now().isoformat(),
    job=job,
    run=run,
    inputs=[
        InputDataset(
            namespace=namespace,
            name="bronze.orders",
            facets={
                "schema": SchemaDatasetFacet(fields=[
                    SchemaField(name="order_id", type="STRING"),
                    SchemaField(name="customer_id", type="STRING"),
                    SchemaField(name="amount", type="DECIMAL")
                ])
            }
        ),
        InputDataset(namespace=namespace, name="bronze.customers")
    ],
    outputs=[
        OutputDataset(
            namespace=namespace,
            name="gold.customer_metrics",
            facets={
                "columnLineage": ColumnLineageDatasetFacet(fields={
                    "total_revenue": {
                        "inputFields": [
                            {"namespace": namespace,
                             "name": "bronze.orders",
                             "field": "amount"}
                        ],
                        "transformationType": "AGGREGATION",
                        "transformationDescription": "SUM(amount)"
                    }
                })
            }
        )
    ],
    producer="https://github.com/company/data-pipeline"
)
client.emit(start_event)

# 작업 완료 이벤트
complete_event = RunEvent(
    eventType=RunState.COMPLETE,
    eventTime=datetime.now().isoformat(),
    job=job, run=run
)
client.emit(complete_event)

print(f"Lineage event emitted for run: {run.runId}")

Practical Conversation

I want to change a source table column, but I don't know what it will affect.
Check the lineage graph. If you look up the downstream of that column in DataHub or dbt docs, you can see all the affected models and dashboards. You must perform an impact analysis before making the change.
How do you use lineage when handling a GDPR personal data deletion request?
Lineage is used to trace which tables and pipelines a specific individual's data has passed through. You identify all downstream tables that contain the email column and determine the scope of what needs to be deleted. This is used to respond to the 'right to be forgotten.' Column-level lineage makes this more accurate.

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

It seems that lineage is not being collected automatically in an Airflow DAG.
You need to add the OpenLineage configuration to airflow.cfg. Specify the transport URL in the [openlineage] section, and custom Operators must implement an OpenLineage Extractor. Most official Providers support it automatically, so check the version.

Cautions

  • Legacy systems and manual processes are difficult to cover with automatic lineage collection, so manual registration is required.
  • Large-scale lineage graphs make visualization complex, so filtering and level-limiting features are important.
  • Column-level lineage depends on SQL parsing accuracy, so complex dynamic SQL may result in missed tracking.
  • Because metadata formats differ from tool to tool, adopting a standard protocol such as OpenLineage is recommended.
  • dbt automatically generates lineage information from manifest.json, and it integrates easily with DataHub/Marquez.

Learn More