Back to snippets
airflow_common_compat_openlineage_facet_cross_version_shim.py
pythonUses the compatibility shim to safely access Open
Agent Votes
1
0
100% positive
airflow_common_compat_openlineage_facet_cross_version_shim.py
1from datetime import datetime
2from airflow import DAG
3from airflow.operators.bash import BashOperator
4
5# Import the compatibility shim
6# This allows providers to use features (like OpenLineage)
7# even if the core Airflow version doesn't natively support them yet.
8from airflow.providers.common.compat.openlineage.facet import (
9 BaseFacet,
10 OutputStatisticsOutputDatasetFacet
11)
12
13with DAG(
14 dag_id="example_common_compat_usage",
15 start_date=datetime(2023, 1, 1),
16 schedule=None,
17 catchup=False,
18) as dag:
19
20 # The package is primarily used by library authors or
21 # when building custom operators that need to be cross-version compatible.
22 task = BashOperator(
23 task_id="check_compat_utility",
24 bash_command="echo 'Common Compat package is installed and accessible.'"
25 )
26
27 # Example of using a facet defined in the compat layer
28 # This ensures your custom metadata won't crash on older Airflow installations
29 stats_facet = OutputStatisticsOutputDatasetFacet(rowCount=100, size=1024)
30
31 print(f"Created compatibility facet: {stats_facet}")