Branching

Einführung in Apache Airflow mit Python

Mike Metzger

Data Engineer

Branching

Branching in Airflow:

  • Bietet bedingte Logik
  • Mit BranchPythonOperator
  • from airflow.operators.python import BranchPythonOperator
  • Nimmt ein python_callable, das die nächste Task-ID (oder Liste von IDs) zurückgibt
Einführung in Apache Airflow mit Python

Branching-Beispiel

def branch_test(**kwargs):
  if int(kwargs['ds_nodash']) % 2 == 0:
    return 'even_day_task'
  else:
    return 'odd_day_task'
Einführung in Apache Airflow mit Python

Branching-Beispiel

def branch_test(**kwargs):
  if int(kwargs['ds_nodash']) % 2 == 0:
    return 'even_day_task'
  else:
    return 'odd_day_task'

branch_task = BranchPythonOperator(task_id='branch_task',dag=dag, provide_context=True, python_callable=branch_test)
start_task >> branch_task >> even_day_task >> even_day_task2
branch_task >> odd_day_task >> odd_day_task2
Einführung in Apache Airflow mit Python

Branching-Graphansicht

DAG-Graphansicht mit Branching

Einführung in Apache Airflow mit Python

Branching gerade Tage

Verzweigungs-Graphansicht – gerade Tage

Einführung in Apache Airflow mit Python

Branching ungerade Tage

Verzweigungs-Graphansicht – ungerade Tage

Einführung in Apache Airflow mit Python

Lass uns üben!

Einführung in Apache Airflow mit Python

Preparing Video For Download...