Branching

Introducción a Apache Airflow en Python

Mike Metzger

Data Engineer

Branching

Branching en Airflow:

  • Lógica condicional
  • Con BranchPythonOperator
  • from airflow.operators.python import BranchPythonOperator
  • Recibe un python_callable que devuelve el id (o lista) de la siguiente tarea
Introducción a Apache Airflow en Python

Ejemplo de branching

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

Ejemplo de branching

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
Introducción a Apache Airflow en Python

Vista de gráfico: branching

Vista de gráfico de DAG con branching

Introducción a Apache Airflow en Python

Branching: días pares

Vista de gráfico de branching - días pares

Introducción a Apache Airflow en Python

Branching: días impares

Vista de gráfico de branching - días impares

Introducción a Apache Airflow en Python

¡Vamos a practicar!

Introducción a Apache Airflow en Python

Preparing Video For Download...