Last active
December 25, 2018 19:55
-
-
Save kaxil/335d90da8821a4e515046ff0f470fc97 to your computer and use it in GitHub Desktop.
Using Airflow params argument
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# You can pass `params` dict to DAG object | |
default_args = { | |
'owner': 'airflow', | |
'depends_on_past': False, | |
'start_date': airflow.utils.dates.days_ago(2), | |
} | |
dag = DAG( | |
dag_id='airflow_tutorial_2', | |
default_args=default_args, | |
schedule_interval=None, | |
params={ | |
"param1": "value1", | |
"param2": "value2" | |
} | |
) | |
bash = BashOperator( | |
task_id='bash', | |
bash_command='echo {{ params.param1 }}', # Output: value1 | |
dag=dag | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Passing `params` dict in `default_arg` dict | |
default_args = { | |
'owner': 'airflow', | |
'depends_on_past': False, | |
'start_date': airflow.utils.dates.days_ago(2), | |
'params': { | |
"param1": "value2", | |
"param2": "value1" | |
} | |
} | |
dag = DAG( | |
dag_id='airflow_tutorial_2', | |
default_args=default_args, | |
schedule_interval=None, | |
) | |
bash = BashOperator( | |
task_id='bash', | |
bash_command='echo {{ params.param1 }}', # Output: value2 | |
dag=dag | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Passing `params` dict in tasks | |
default_args = { | |
'owner': 'airflow', | |
'depends_on_past': False, | |
'start_date': airflow.utils.dates.days_ago(2), | |
} | |
dag = DAG( | |
dag_id='airflow_tutorial_2', | |
default_args=default_args, | |
schedule_interval=None, | |
) | |
bash = BashOperator( | |
task_id='bash', | |
bash_command='echo {{ params.param1 }}', # Output: value3 | |
params={ | |
"param1": "value3", | |
"param2": "value4" | |
} | |
dag=dag | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# You can override `params` dict passed in DAG object in `default_arg` dict | |
default_args = { | |
'owner': 'airflow', | |
'depends_on_past': False, | |
'start_date': airflow.utils.dates.days_ago(2), | |
'params': { | |
"param1": "value2", | |
"param2": "value2" | |
} | |
} | |
dag = DAG( | |
dag_id='airflow_tutorial_2', | |
default_args=default_args, | |
schedule_interval=None, | |
params={ | |
"param1": "value1", | |
"param2": "value2" | |
} | |
) | |
# You can override `params` dict passed in DAG object or `default_arg` in each individual tasks | |
bash = BashOperator( | |
task_id='bash', | |
bash_command='echo {{ params.param1 }}', # Output: value3 | |
params={ | |
"param1": "value3" | |
} | |
dag=dag | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment