我想使用 Airflow 中的执行时间并添加一天:
'{{(execution_date + timedelta(days=1)).strftime("%Y-%m-%d")}}'
Run Code Online (Sandbox Code Playgroud)
当我执行这个时我得到
jinja2.exceptions.UndefinedError: 'timedelta' is undefined
Run Code Online (Sandbox Code Playgroud)
如何获得执行时间加一天?
我在这里找到了答案:https://diogoalexandrefranco.github.io/about-airflow-date-macros-ds-and-execution-date/
您可以使用:
'{{(execution_date + macros.timedelta(days=1)).strftime("%Y-%m-%d")}}'
Run Code Online (Sandbox Code Playgroud)
宏对象公开了常见的Python函数和库,例如macros.datetime和macros.timedelta