airflow的宏

airflow的宏和变量可以用于模版(templates)。

默认变量

所有的模版中都可以访问airflow引擎传输默认的变量。

变量 描述
{{ ds }} the execution date as YYYY-MM-DD
{{ ds_nodash }} the execution date as YYYYMMDD
{{ prev_ds }} the previous execution date as YYYY-MM-DD if {{ ds }} is 2018-01-08and schedule_interval is @weekly, {{ prev_ds }} will be 2018-01-01
{{ prev_ds_nodash }} the previous execution date as YYYYMMDD if exists, else None
{{ next_ds }} the next execution date as YYYY-MM-DD if {{ ds }} is 2018-01-01 and schedule_interval is @weekly, {{ next_ds }} will be 2018-01-08
{{ next_ds_nodash }} the next execution date as YYYYMMDD if exists, else None
{{ yesterday_ds }} the day before the execution date as YYYY-MM-DD
{{ yesterday_ds_nodash}} the day before the execution date as YYYYMMDD
{{ tomorrow_ds }} the day after the execution date as YYYY-MM-DD
{{ tomorrow_ds_nodash }} the day after the execution date as YYYYMMDD
{{ ts }} same as execution_date.isoformat(). Example: 2018-01-01T00:00:00+00:00
{{ ts_nodash }} same as ts without -, : and TimeZone info. Example: 20180101T000000
{{ ts_nodash_with_tz }} same as ts without - and :. Example: 20180101T000000+0000
{{ execution_date }} the execution_date (pendulum.Pendulum)
{{ prev_execution_date}} the previous execution date (if available) (pendulum.Pendulum)
{{prev_execution_date_success }} execution date from prior successful dag run (if available) (pendulum.Pendulum)
{{prev_start_date_success}} start date from prior successful dag run (if available) (pendulum.Pendulum)
{{ next_execution_date}} the next execution date (pendulum.Pendulum)
{{ 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 which can be overridden by the dictionary passed through trigger_dag -c if you enableddag_run_conf_overrides_params in ``airflow.cfg`
{{ 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.confwhich 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

宏暴露对象在你的模版中,在模版的宏命名空间有效。
一些常见的变量和方法

Variable Description
macros.datetime The standard lib’s datetime.datetime
macros.timedelta The standard lib’s datetime.timedelta
macros.dateutil A reference to the dateutil package
macros.time The standard lib’s datetime.time
macros.uuid The standard lib’s uuid
macros.random The standard lib’s random

参考:
https://airflow.apache.org/docs/stable/macros.html

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 本文将介绍 Airflow 这一款优秀的调度工具。主要包括 Airflow 的服务构成、Airflow 的 Web...
    a7f00a9019ae阅读 62,925评论 6 42
  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 9,504评论 0 13
  • 本文重点介绍应用程序的启动过程,应用程序的启动过程实际上就是应用程序中的默认Activity的启动过程,本文将详细...
    天宇sonny阅读 411评论 1 0
  • 天气这么冷。原因是中国的大部分大面积的下雪。柯铁给他妈发的视频,可以看到大雪飘飞的样子。 阳新正在下起一场大雪。雪...
    6e9c1462d480阅读 86评论 0 0
  • 目录:《猎捕关东一号》目录 上一章:《猎捕关东一号》第三十五章 监狱逞威 下一章:《猎捕关东一号》第三十七章 报仇...
    张小贝_阅读 490评论 0 3