气流:使用BigQueryCheckeCoperator的模板参数

发布于 2025-02-10 04:25:00 字数 582 浏览 3 评论 0原文

我想在气流中使用bigQueryCheckeCoperator,查询需要将执行日期作为参数。我写了以下操作员检查当前日期,但我不明白如何使用DAG的execution_date

BigQueryCheckOperator(
        task_id='mytask',
        retry_delay=10,
        retries=2,
        sql="""
           SELECT
            COUNT(*)
           FROM
            mydataset.mytable AS tb
           WHERE
            DATE(tb.date) = '{check_date}'
        """.format(
            check_date=(datetime.now()).strftime("%Y-%m-%d")
        ),
        bigquery_conn_id='my_google_cloud_conn',
        dag=dag)

你能帮我吗?

I would like to use the BigQueryCheckOperator in airflow where the query needs to have the execution date as parameter. I have written the following operator that check the current date, but I do not understand how to use the execution_date of the dag.

BigQueryCheckOperator(
        task_id='mytask',
        retry_delay=10,
        retries=2,
        sql="""
           SELECT
            COUNT(*)
           FROM
            mydataset.mytable AS tb
           WHERE
            DATE(tb.date) = '{check_date}'
        """.format(
            check_date=(datetime.now()).strftime("%Y-%m-%d")
        ),
        bigquery_conn_id='my_google_cloud_conn',
        dag=dag)

Could you help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风夜微凉 2025-02-17 04:25:00

您可以使用jinja模板和变量= {{ds}}

BigQueryCheckOperator(
        task_id='mytask',
        retry_delay=10,
        retries=2,
        sql="""
           SELECT
            COUNT(*)
           FROM
            mydataset.mytable AS tb
           WHERE
            DATE(tb.date) = DATE('{{ ds }}')""",
        bigquery_conn_id='my_google_cloud_conn',
        dag=dag)

You can use Jinja template and variable = {{ ds }}

BigQueryCheckOperator(
        task_id='mytask',
        retry_delay=10,
        retries=2,
        sql="""
           SELECT
            COUNT(*)
           FROM
            mydataset.mytable AS tb
           WHERE
            DATE(tb.date) = DATE('{{ ds }}')""",
        bigquery_conn_id='my_google_cloud_conn',
        dag=dag)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文