- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的代码:
EXEC_TIMESTAMP = "{{ execution_date.strftime('%Y-%m-%d %H:%M') }}"
query = """
select ... where date_purchased between TIMESTAMP_TRUNC(cast ( {{ params.run_timestamp }} as TIMESTAMP), HOUR, 'UTC') ...
"""
generate_op = BigQueryOperator(
bql=query,
destination_dataset_table=table_name,
task_id='generate',
bigquery_conn_id=CONNECTION_ID,
use_legacy_sql=False,
write_disposition='WRITE_TRUNCATE',
create_disposition='CREATE_IF_NEEDED',
query_params={'run_timestamp': EXEC_TIMESTAMP},
dag=dag)
这应该有效,但实际上无效。渲染选项卡显示:
between TIMESTAMP_TRUNC(cast ( as TIMESTAMP), HOUR, 'UTC')
缺少日期。它正在变得虚无。
我该如何解决这个问题?此运算符没有 provide_context=True
。我不知道该怎么办。
最佳答案
Luis,query_params
不是您可以在模板上下文中引用的params
。它们没有添加到其中。由于 params
为空,因此您的 {{ params.run_timestamp }}
为 ""
或 None
。如果您将其更改为 params={'run_timestamp':…}
它仍然会有问题,因为 params
值未模板化。因此,当您使用模板化字段 bql
来包含 {{ params.run_timestamp }}
时,您将准确了解 params: {'run_timestamp': …str ... }
在没有对该值进行任何递归扩展的情况下填写。你应该得到 {{ execution_date.strftime('%Y-%m-%d %H:%M') }}
。
让我尝试为您重写这个(但我不确定周围的括号是否正确转换):
generate_op = BigQueryOperator(
sql="""
select ...
where date_purchased between
TIMESTAMP_TRUNC(cast('{{execution_date.strftime('%Y-%m-%d %H:%M')}}') as TIMESTAMP), HOUR, 'UTC')
...
""",
destination_dataset_table=table_name,
task_id='generate',
bigquery_conn_id=CONNECTION_ID,
use_legacy_sql=False,
write_disposition='WRITE_TRUNCATE',
create_disposition='CREATE_IF_NEEDED',
dag=dag,
)
您可以 see the bql
and sql
fields are templated .然而 bql
field is deprecated and removed在后面的代码中。
关于airflow - 如何将 BigQueryOperator 与 execution_date 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53828163/
我正在尝试在 Bigquery 运算符中对 params 字段进行模板化,如下所示。 t3 = MyBigQueryOperator( task_id='autoplay_calc',
这是我的代码: EXEC_TIMESTAMP = "{{ execution_date.strftime('%Y-%m-%d %H:%M') }}" query = """ se
我正在使用 Airflow 的 BigQueryOperator 使用 write_disposition='WRITE_TRUNCATE' 填充 BQ 表。问题是每次任务运行时,它都会将表模式和列模
我正在尝试使用 Airflow 从 BigQueryOperator 获取结果,但我找不到执行此操作的方法。我尝试调用 bq_cursor 成员(在 1.10 中可用)中的 next() 方法,但它返
这是我的运算符(operator): bigquery_check_op = BigQueryOperator( task_id='bigquery_check', bql=SQL_Q
我有一个要使用 BigQueryOperator 运行的查询。每天,它将运行过去 21 天。 sql 文件保持不变,但传递给文件的日期发生了变化。因此,例如今天,它将为今天的日期运行,然后为昨天的日期
我正在尝试在 ETL 管道中将一堆 BigQuery SQL 命令链接在一起,其中一些输出和输入将带有时间戳。 from datetime import timedelta import airflo
我有一个简单的 DAG from airflow import DAG from airflow.contrib.operators.bigquery_operator import BigQuery
我是一名优秀的程序员,十分优秀!