访问气流中的“ ds”变量 [英] Accessing the 'ds' variable in airflow

查看:322
本文介绍了访问气流中的“ ds”变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够使用如下所示的python代码访问宏:

I am able to access the macros in python code like below:

partition_dt = macros.ds_add(ds, 1)

但是我不知道如何掌握 ds 变量本身,似乎只能在模板中访问。

But i am not able to figure out how to get hold of the ds variable itself which seemingly can only be accessed in templates. Any pointers?

推荐答案

我假设您要调用内置于AirFlow ds的默认变量之一-执行日期为YYYY -MM-DD

I assume you want to call one of the default variables built-in AirFlow ds - the execution date as YYYY-MM-DD

仅呼叫ds,您可以执行以下操作:

To call just ds, you can do:

EXEC_DATE = '{{ ds }}'

调用您想要的内容-macros.ds_add:

To call what you wanted - macros.ds_add:

EXEC_DATE = '{{ macros.ds_add(ds, 1) }}'

并以这种方式加载:

T1 = BashOperator(\
        task_id='test_ds',
        bash_command='echo ' + EXEC_DATE
        dag=DAG)

如果要格式化它(如我所必须的那样),则可以执行以下操作:

In case you want to format it (like I had to), you can do:

EXEC_DATE = '{{ macros.ds_format(macros.ds_add(ds, 1), "%Y-%m-%d", "%Y%m%d") }}'

这篇关于访问气流中的“ ds”变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆