1. Airflow 날짜 Template 변수 이해

데이터 추출 예시

Daily ETL처리를 위한 조회 쿼리 (2023/02/25 0시 실행)

SELECT NAME, ADDRESS
FROM TBL_REG
WHERE REG_DATE BETWEEN TIMESTAMP('2023-02-24 00:00:00')
	AND TIMESTAMP('2023-02-24 23:59:59')

데이터 관점의 시작일 : 2023-02-24

데이터 관점의 종료일 : 2023-02-25

 

이전 배치일 (논리적 기준일)

ex) 2023-02-24

= data_interval_start

= dag_run.logical_date

= ds (yyyy-mm-dd 형식)

= ts (타임스탬프)

= execution_date (과거버전) : 현재는 사용하지 않음

 

배치일

ex) 2023-02-25

= data_interval_end

= next_execution_date (과거버전) : 현재는 사용하지 않음

 

 

2. 모든 Template 날짜 변수 출력해보기

dags_python_show_templates.py

import datetime
import pendulum

from airflow.models.dag import DAG
from airflow.decorators import task

with DAG(
    dag_id="dags_python_show_templates",
    schedule="30 9 * * *",
    start_date=pendulum.datetime(2023, 3, 10, tz="Asia/Seoul"),
    catchup=True, #True는 설정일부터 현재까지 한번에 모든 날짜가 실행됨.
) as dag:
    
    @task(task_id='python_task')
    def show_templates(**kwargs):
        from pprint import pprint #예쁘게 출력해주는 print
        pprint(kwargs)

    show_templates()

결과:

'Airflow' 카테고리의 다른 글

S4-ch0505. Bahs 오퍼레이터 with macro  (0) 2024.02.29
S4-0504. Python 오퍼레이터 with Template  (0) 2024.02.28
S4-502. Bash 오퍼레이터 with Template  (0) 2024.02.27
S4-ch501. Jinja 템플릿  (0) 2024.02.27
파이썬 데커레이터  (0) 2024.02.26

+ Recent posts