我正在将Airflow 1.10.1与Python 3.5配合使用,假设我扩展了BaseOperator
operator并将其.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
您缺少“ template_fields”参数,如下所示:
template_fields = ('sql', 'destination_dataset_table', 'labels')
template_ext = ('.sql', )
但即使我说
template_fields = ('params')
这也不起作用。template_fields应该是包含模板化字符串的字段,而不是值。在您的情况下,包含您的json文件路径的文件
通过添加工作
template_fields = ('report_file_path', )
。谢谢!