XCom으로 태스크 간 데이터 전달

Python으로 배우는 Apache Airflow 입문

Mike Metzger

Data Engineer

XCom이란?

  • "Cross Communication"
    • 태스크 간 데이터 교환 가능
  • Airflow 메타데이터 데이터베이스에 저장
    • 소량의 데이터 전달
    • 파일명, URI, 행 수 등

Airflow 태스크 간 소량 데이터를 전달하는 XCom 개요 그림

Python으로 배우는 Apache Airflow 입문

XCom으로 전송하지 말아야 할 것

  • 대용량 파일
  • DataFrame
  • 전체 데이터베이스
  • 대용량 이미지

대용량 파일, DataFrame 등 XCom으로 전송하면 안 되는 데이터 유형 그림

Python으로 배우는 Apache Airflow 입문

XCom 구현

  • XCom 사용 방법은 다양
  • TaskFlow API에 집중
  • @task로 이미 수행한 작업의 확장
Python으로 배우는 Apache Airflow 입문

XCom 예시

@dag(dag_id='Example_XCom')
def example_xcom():

@task def get_data(): return data
@task(multiple_outputs=True) def clean_data(sourcedata): return clean(sourcedata) # Example, not implemented
clean_data(get_data()) example_xcom()
Python으로 배우는 Apache Airflow 입문

XCom 의존성

  • XCom은 의존성 순서를 자동으로 정의
  • 예시
    clean_data(get_data())
    
  • 개념적으로 get_data() >> clean_data()와 동일
  • 추가 예시
     result = clean_data(get_data())
     result >> alert_when_complete()
    
Python으로 배우는 Apache Airflow 입문

XCom 데이터 확인

키, DAG, 태스크별로 저장된 값을 나열하는 Airflow XCom 페이지

Python으로 배우는 Apache Airflow 입문

연습해 봅시다!

Python으로 배우는 Apache Airflow 입문

Preparing Video For Download...