Google bigquery BigQueryOperator中的pull xcom
我正试图运行一个BigQueryOperator,其中包含一些基于使用xcom的上一个任务的动态参数(我设法使用BashOperator在xcom_push=True的情况下推送它) 我想用下面的方法就可以了Google bigquery BigQueryOperator中的pull xcom,google-bigquery,airflow,apache-airflow-xcom,Google Bigquery,Airflow,Apache Airflow Xcom,我正试图运行一个BigQueryOperator,其中包含一些基于使用xcom的上一个任务的动态参数(我设法使用BashOperator在xcom_push=True的情况下推送它) 我想用下面的方法就可以了 def get_next_run_date(**context): last_date = context['task_instance'].xcom_pull(task_ids=['get_autoplay_last_run_date'])[0].rstrip() las
def get_next_run_date(**context):
last_date = context['task_instance'].xcom_pull(task_ids=['get_autoplay_last_run_date'])[0].rstrip()
last_date = datetime.strptime(last_date, "%Y%m%d").date()
return last_date + timedelta(days=1)
t3 = BigQueryOperator(
task_id='autoplay_calc',
bql='autoplay_calc.sql',
params={
"env" : deployment
,"region" : region
,"partition_start_date" : get_next_run_date()
},
bigquery_conn_id='gcp_conn',
use_legacy_sql=False,
write_disposition='WRITE_APPEND',
allow_large_results=True,
#provide_context=True,
destination_dataset_table=reporting_project + '.pa_reporting_public_batch.autoplay_calc',
dag=dag
)`
但是使用上面的方法会给我提供一个带有“task\u instance”错误的坏Dag错误。您是否尝试过使用上下文['ti'].xcom\u pull()?您是否尝试过使用上下文['ti'].xcom\u pull()?您使用它的方式不正确 您不能在
params
中使用xcom
。您需要在bql/sql
参数中使用它。sql文件,autoplay\u calc.sql
可以包含以下内容
select * from XYZ where date == "{{xcom_pull(task_ids=['get_autoplay_last_run_date'])[0].rstrip() }}"
你用错了它 您不能在
params
中使用xcom
。您需要在bql/sql
参数中使用它。sql文件,autoplay\u calc.sql
可以包含以下内容
select * from XYZ where date == "{{xcom_pull(task_ids=['get_autoplay_last_run_date'])[0].rstrip() }}"