airflow的参数

来源[https://airflow.apache.org/code.html?highlight=ds_nodash#api-reference](https://airflow.apache.org/code.html?highlight=ds_nodash#api-reference)

Default Variables

VariableDescription
{{ ds }}the execution date as YYYY-MM-DD
{{ ds_nodash }}the execution date as YYYYMMDD
{{ yesterday_ds }}yesterday’s date as YYYY-MM-DD
{{ yesterday_ds_nodash }}yesterday’s date as YYYYMMDD
{{ tomorrow_ds }}tomorrow’s date as YYYY-MM-DD
{{ tomorrow_ds_nodash }}tomorrow’s date as YYYYMMDD
{{ ts }}same as execution_date.isoformat()
{{ ts_nodash }}same as ts without - and :
{{ execution_date }}the execution_date, (datetime.datetime)
{{ prev_execution_date }}the previous execution date (if available) (datetime.datetime)
{{ next_execution_date }}the next execution date (datetime.datetime)
{{ dag }}the DAG object
{{ task }}the Task object
{{ macros }}a reference to the macros package, described below
{{ task_instance }}the task_instance object
{{ end_date }}same as {{ ds }}
{{ latest_date }}same as {{ ds }}
{{ ti }}same as {{ task_instance }}
{{ params }}a reference to the user-defined params dictionary
{{ var.value.my_var }}global defined variables represented as a dictionary

{{ var.json.my_var.path }}

global defined variables represented as a dictionary with deserialized JSON object, append the path to the key within the JSON object

{{ task_instance_key_str }}

a unique, human-readable key to the task instance formatted {dag_id}_{task_id}_{ds}

{{ conf }}

the full configuration object located at airflow.configuration.conf which represents the content of your airflow.cfg

{{ run_id }}the run_id of the current DAG run
{{ dag_run }}a reference to the DagRun object

{{ test_mode }}

whether the task instance was called using the CLI’s test subcommand

Macros

VariableDescription
macros.datetimeThe standard lib’s datetime.datetime
macros.timedelta

The standard lib’s datetime.timedelta

macros.dateutilA reference to the dateutil package
macros.timeThe standard lib’s time
macros.uuidThe standard lib’s uuid
macros.randomThe standard lib’s random
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Airflow可以通过使用`PythonOperator`和`Boto3`库中的`glue`模块来触发AWS Glue Job的执行。这里的参数可以从数据库中获取,然后传递给AWS Glue Job。具体步骤如下: 1. 在Airflow DAG中,使用`PythonOperator`定义一个Python函数,用于从数据库中获取参数并传递给AWS Glue Job。 ```python from airflow import DAG from airflow.operators.python_operator import PythonOperator import boto3 def trigger_glue_job(**kwargs): # 获取参数 db_conn = kwargs['redshift_conn_id'] db_sql = kwargs['sql'] glue_job_name = kwargs['glue_job'] # 从数据库中获取参数 redshift_hook = PostgresHook(postgres_conn_id=db_conn) conn = redshift_hook.get_conn() cursor = conn.cursor() cursor.execute(db_sql) result = cursor.fetchone() # 将参数传递给AWS Glue Job glue = boto3.client('glue') response = glue.start_job_run( JobName=glue_job_name, Arguments={ '--arg1': result[0], '--arg2': result[1], # ... } ) ``` 2. 在DAG中创建一个`PythonOperator`,将刚才定义的Python函数作为其参数。 ```python from datetime import datetime, timedelta default_args = { 'owner': 'airflow', 'start_date': datetime(2022, 1, 1), 'retries': 1, 'retry_delay': timedelta(minutes=1) } with DAG('my_dag', default_args=default_args, schedule_interval='@daily') as dag: # 定义PythonOperator,将刚才定义的Python函数作为其参数 trigger_glue_job_task = PythonOperator( task_id='trigger_glue_job', python_callable=trigger_glue_job, op_kwargs={ 'redshift_conn_id': 'my_redshift_connection', 'sql': 'SELECT arg1, arg2 FROM my_table WHERE id=1', 'glue_job': 'my_glue_job' } ) ``` 这样,当DAG运行时,`trigger_glue_job`任务将被触发,它会从数据库中获取参数,并将参数传递给AWS Glue Job。AWS Glue Job会使用这些参数来执行相应的任务。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值