如何在Airflow中从文件执行SQL查询?(PostgresSQL运算符)

2024-09-20 01:44:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用postgresql运算符。任务如下:

emailage_transformations = PostgresOperator(
    task_id = 'emailage_transformations',
    sql = '/home/ubuntu/airflow_ci/current/scripts/antifraud/emailage_transformations.sql',
    postgres_conn_id = 'redshift',
    autocommit = True,
    dag = dag)

起初,文件的内容是下一个:

^{pr2}$

我得到的错误是

jinja2.exceptions.TemplateNotFound: /home/ubuntu/airflow_ci/current/scripts/antifraud/emailage_transformations.sql

因此,我在查询中添加了几个括号,以符合jinja2模板,现在文件代码是:

{select cd_pedido_nr,fraud_score,risk_band,ip_risk_level
into antifraud.stg_emailage_id_pedido
from antifraud.stg_emailage_id_email e
left join antifraud.info_emails i on id_email = cd_email_nr
;}

然而,我仍然有同样的错误。我该怎么解决呢?在


Tags: 文件ciidhomesqlemailubuntu错误