访问气流中的“ ds”变量

编程入门 行业动态 更新时间:2024-10-28 00:23:34
本文介绍了访问气流中的“ 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”变量

本文发布于:2023-11-23 17:32:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622299.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:气流   变量   ds

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!