Opérateurs Airflow

Introduction à Apache Airflow en Python

Mike Metzger

Data Engineer

Opérateurs

  • Représentent une tâche unique dans un workflow.
  • S’exécutent de façon indépendante (en général).
  • Ne partagent généralement pas d’informations.
  • Différents opérateurs pour différents besoins.
# New way, Airflow 2.x+
EmptyOperator(task_id='example')

# Old way, Airflow <2.0
EmptyOperator(task_id='example', dag=dag_name)
Introduction à Apache Airflow en Python

BashOperator

BashOperator(
    task_id='bash_example',
    bash_command='echo "Example!"',
    # Next line only for Airflow before version 2
    dag=dag
)
BashOperator(
    task_id='bash_script_example',
    bash_command='runcleanup.sh',
)
  • Exécute une commande ou un script Bash donné.
  • Lance la commande dans un répertoire temporaire.
  • Peut définir des variables d’environnement pour la commande.
Introduction à Apache Airflow en Python

Exemples BashOperator

from airflow.operators.bash import BashOperator

example_task = BashOperator(task_id='bash_ex', bash_command='echo 1', )
bash_task = BashOperator(task_id='clean_addresses',
  bash_command='cat addresses.txt | awk "NF==10" > cleaned.txt',
)
Introduction à Apache Airflow en Python

Pièges des opérateurs

  • Aucune garantie d’exécution au même endroit / dans le même environnement.
  • Peut nécessiter un usage intensif de variables d’environnement.
  • Difficile d’exécuter des tâches avec des privilèges élevés.
Introduction à Apache Airflow en Python

Passons à la pratique !

Introduction à Apache Airflow en Python

Preparing Video For Download...