Branchement

Introduction à Apache Airflow en Python

Mike Metzger

Data Engineer

Branchement

Le branchement dans Airflow :

  • Apporte une logique conditionnelle
  • Avec BranchPythonOperator
  • from airflow.operators.python import BranchPythonOperator
  • Prend un python_callable qui renvoie l’ID de la prochaine tâche (ou une liste d’IDs) à suivre
Introduction à Apache Airflow en Python

Exemple de branchement

def branch_test(**kwargs):
  if int(kwargs['ds_nodash']) % 2 == 0:
    return 'even_day_task'
  else:
    return 'odd_day_task'
Introduction à Apache Airflow en Python

Exemple de branchement

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
Introduction à Apache Airflow en Python

Vue du graphe de branchement

Vue du graphe du DAG de branchement

Introduction à Apache Airflow en Python

Branchement jours pairs

Vue du graphe de branchement - jours pairs

Introduction à Apache Airflow en Python

Branchement jours impairs

Vue du graphe de branchement - jours impairs

Introduction à Apache Airflow en Python

Passons à la pratique !

Introduction à Apache Airflow en Python

Preparing Video For Download...