Reputation: 642
I have a jinja template that refer to an sql file which is going to be run by the Airflow operator. (According to this Airflow doc)
execute_query = BigQueryInsertJobOperator(
task_id="execute_query_task",
configuration={
"query": {
"query" : "{% include 'folder/final_tableA.sql' %}",
"useLegacySql": False,
}
}
)
which it work perfectly. But my question here is that what if I have to dynamically change the file name or folder. This operator run inside a for loop of table list e.g. tableA, tableB, tableC . . . How can I format the string inside this template?
This is what I tried but failed
table = "tableB"
execute_query = BigQueryInsertJobOperator(
.
.
.
" "query" : {% include 'folder/final_{}.sql'.format(table) %}"
and got this error
jinja2.exceptions.TemplateNotFound: folder/final_{'json': None, 'value': None}.sql
Upvotes: 0
Views: 740
Reputation: 808
Not seeing a DAG doesn't help but have you tried?
"query": "{{% include 'folder/final_{}.sql'%}}".format(table)
The {{
is to do escaping for templating string with format
.
Upvotes: 1