我目前在 Apache Airflow 中使用以下语句
s10_test_load = bigquery.BigQueryInsertJobOperator(
task_id="10_test_load",
configuration={
"query": {
"query": "{% include './scripts/10_test_load.sql' %}",
"useLegacySql": False,
},
},
)
该语句工作正常,正在从脚本文件执行 sql。
我想动态使用变量中的文件名,如下所示
file_name='./scripts/10_test_load.sql'
s10_test_load = bigquery.BigQueryInsertJobOperator(
task_id="10_test_load",
configuration={
"query": {
"query": "{% include file_name %}",
"useLegacySql": False,
},
},
)
如何在 jinja include 中传递 python 变量?
最佳答案
您可以使用 f 字符串格式并添加一对额外的大括号,如下所示:
file_name='bq/queries/10_test_load.sql'
t2 = BigQueryInsertJobOperator(
task_id="10_test_load",
configuration={
"query": {
"query": f"{{% include '{file_name}' %}}",
"useLegacySql": False,
},
},
)
关于python - Apache Airflow : Pass variable in jinja include,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70324891/