温馨提示:本文翻译自stackoverflow.com,查看原文请点击:python - Airflow jinja2 templated json file
airflow jinja2 python

python - Airflow Jinja2模板化json文件

发布于 2020-03-27 10:55:00

我正在将Airflow 1.10.1与Python 3.5配合使用,假设我扩展了BaseOperatoroperator并将其.json扩展添加template_ext

template_ext = ('.json',)

然后提供.json包含宏占位符模板文件的路径

{
  "kind": "dfareporting#report",
  "name": "{{ params.cm_report_name }}"
}

它具有params通过参数传递给所有dag运算符的参数的占位符default_args

args = {
    # ...
    'params': {
        'cm_report_name': "AAAA"
    }
}

但是由于某种原因,我的宏没有被“ AAAA”代替。

我想复制/粘贴bigquery_operator.py用于.sql文件的模式。

这是操作员的完整代码:https : //gist.github.com/fpopic/64455b8d24acc6a7d3e6d73392b20c9f#file-cm_report_find_update_operator-py-L15

查看更多

查看更多

提问者
fpopic
被浏览
86
Breathe 2019-07-03 22:05

您缺少“ template_fields”参数,如下所示:

template_fields = ('sql', 'destination_dataset_table', 'labels')
template_ext = ('.sql', )