经过多次测试,我想出了这个解决方案,感谢tobi6的评论,他给了我正确的方向。我不得不使用
模板字段
特色。
以下是最终代码:
with DAG('bq_load_file_from_cloud_function', default_args=default_args) as dag:
def get_file_name_from_conf(ds, **kwargs):
return kwargs['dag_run'].conf['fileName']
get_file_name = PythonOperator(
task_id='get_file_name',
provide_context=True,
python_callable=get_file_name_from_conf)
bq_load = GoogleCloudStorageToBigQueryOperator(
task_id='bq_load',
bucket='src_bucket',
source_objects=["{{ task_instance.xcom_pull(task_ids='get_file_name') }}"],
destination_project_dataset_table='project:dataset.table',
write_disposition='WRITE_APPEND')
bq_load.set_upstream(get_file_name)