metadata-ingestion-modules/airflow-plugin/src/datahub_airflow_plugin/example_dags/README.md
This directory contains example DAGs demonstrating various features of the DataHub Airflow plugin.
example_dags/
├── airflow2/ # Airflow 2.x examples (with compatibility layers)
│ ├── lineage_backend_demo.py
│ ├── lineage_backend_taskflow_demo.py
│ ├── snowflake_sample_dag.py
│ ├── mysql_sample_dag.py
│ ├── generic_recipe_sample_dag.py
│ ├── lineage_emission_dag.py
│ └── graph_usage_sample_dag.py
│
├── airflow3/ # Airflow 3.0+ examples (native syntax, no compatibility)
│ ├── lineage_backend_demo.py
│ ├── lineage_backend_taskflow_demo.py
│ └── snowflake_sample_dag.py
│
└── *.py # Legacy examples (deprecated - use airflow2/ or airflow3/)
Use the examples in airflow3/. These DAGs:
schedule instead of schedule_interval)Use the examples in airflow2/. These DAGs:
_airflow_version_specific.pyIf you need DAGs that work on both Airflow 2.x and 3.x:
airflow2/ examples for patterns using get_airflow_compatible_dag_kwargs()days_ago() helper for start_date compatibilityExamples showing how to automatically collect lineage from your Airflow DAGs:
inlets and outlets@task decorator)Examples showing how to ingest metadata from data sources into DataHub:
DatahubEmitterOperator# Airflow 2.x
DAG(
schedule_interval=timedelta(days=1),
default_view="tree", # Removed in Airflow 3
)
# Airflow 3.0+
DAG(
schedule=timedelta(days=1),
# default_view parameter removed
)
# Airflow 2.x
from airflow.hooks.base import BaseHook
# Airflow 3.0+
from airflow.hooks.base_hook import BaseHook
# Airflow 2.x (compatibility helper)
from datahub_airflow_plugin._airflow_version_specific import days_ago
start_date=days_ago(2)
# Airflow 3.0+ (direct)
from datetime import datetime
start_date=datetime(2023, 1, 1)
Copy the appropriate example to your Airflow DAGs folder:
# For Airflow 3.0+
cp airflow3/lineage_backend_demo.py $AIRFLOW_HOME/dags/
# For Airflow 2.x
cp airflow2/lineage_backend_demo.py $AIRFLOW_HOME/dags/
Configure the DataHub connection in Airflow:
airflow connections add datahub_rest_default \
--conn-type datahub-rest \
--conn-host http://localhost:8080
Enable the DAG in the Airflow UI or trigger it manually:
airflow dags trigger datahub_lineage_backend_demo