Introduction
TaskFlow API paradigm is introduced as part of Airflow 2.0 and contrasts this with DAGs written using the traditional paradigm. In this data pipeline, tasks are created based on Python functions simply using the @task decorator. The function name acts as a unique identifier for the task. But how do I use Python and other operators together? Let's check it out.
QuickStart
You just simply add context as a parameter of python function and throw this to some operator inside of it. Below is an example.
@dag()
def dag():
@task()
def python_task(**context):
bash_task = BashOperator(
task_id='bash_task',
bash_command='echo "this is BashOperator"',
)
bash_task.execute(context)
task()
Any Operator is executed internally wiht execute(). So, you can manually write the code in @task decorated python function. But you must offer the context as a payload which contains information of task instance. In this case, "task_id" parameter is required for creating instance of BashOperator, but it is overwritten as "python_task".
'Software Engineering' 카테고리의 다른 글
[Python 문제 풀이] 프로그래머스 '[PCCP 기출문제] 4번 / 수레 움직이기' (0) | 2024.03.17 |
---|---|
Airflow에서 TaskFlow API(@task)와 PythonOperator가 아닌 Operator 같이 사용하기 (0) | 2024.02.02 |
PolarDB에서 OSS에 있는 csv파일 로드하기 (FOREIGN TABLE) (0) | 2024.02.02 |
Github Actions로 초간단 코드 배포하기 (SSH) (0) | 2024.02.02 |
How to read csv file in OSS with PolarDB (1) | 2023.12.27 |