Airflow using template files for PythonOperator

后端 未结 4 1135
遥遥无期
遥遥无期 2021-01-31 04:49

The method of getting a BashOperator or SqlOperator to pick up an external file for its template is somewhat clearly documented, but looking at the Pyt

4条回答
  •  执念已碎
    2021-01-31 05:36

    I don't think this is really possible. But the following workaround might be helpful:

    def templated_function(ds, **kwargs):
        kwargs['ds'] = ds                                # put ds into 'context'
        task = kwargs['task']                            # get handle on task
        templ = open(kwargs['templates_dict']['file1']).read() # get template
        sql = task.render_template('', tmpl, kwargs)           # render it
        pp.pprint(sql)
    

    Would love a better solution, though!

提交回复
热议问题