我是Google Cloud Composer的新手,遇到了我创建的DAG中似乎很奇怪的问题。我有一个从云存储中获取tar.gz文件,将其重新压缩为.gz文件,然后将.gz文件加载到BigQuery的过程。昨天,我尝试在此过程中添加一个新步骤,该步骤是将已创建的“碎片”插入新表。
在更改DAG执行中的步骤顺序之前,我无法执行此操作。在DAG中,我有一个名为“ delete_tar_gz_files_op”的步骤。在“ insert_daily_file_into_nli_table_op”之前执行此操作时,插入操作永远不会运行(Composer中没有故障,似乎根本没有运行)。当我交换这两个步骤的顺序而没有其他更改代码时,插入将按预期工作。有谁知道这可能是什么原因?我不知道为什么会发生这种情况,因为这两个步骤根本不相关。一个从一个大查询表到另一个大查询表执行插入查询。另一个删除云存储中的tar.gz文件。
我目前执行的dag执行命令:
initialize >> FilesToProcess >> download_file >> convert_task >> upload_task >> gcs_to_bq >> archive_files_op >> insert_daily_file_into_nli_table_op >> delete_tar_gz_files_op
使用了一些代码:
#The big query operator inserts the files from the .gz file into a table in big query.
gcs_to_bq = GoogleCloudStorageToBigQueryOperator(
task_id='load_basket_data_into_big_query'+job_desc,
bucket="my-processing-bucket",
bigquery_conn_id='bigquery_default',
create_disposition='CREATE_IF_NEEDED',
write_disposition='WRITE_TRUNCATE',
compression='GZIP',
source_objects=['gzip/myzip_'+process_date+'.gz'],
destination_project_dataset_table='project.dataset.basket_'+clean_process_date,
field_delimiter='|',
skip_leading_rows=0,
google_cloud_storage_conn_id="bigquery_default",
schema_object="schema.json",
dag=dag
)
#The created shard is then inserted into basket_raw_nli.basket_nli. This is a partitioned table which contains only the NLI subtype
insert_daily_file_into_nli_table_op = bigquery_operator.BigQueryOperator(
task_id='insert_daily_file_into_nli_table_op_'+job_desc,
bql=bqQuery,
use_legacy_sql=False,
bigquery_conn_id='bigquery_default',
write_disposition='WRITE_APPEND',
allow_large_results=True,
destination_dataset_table=False,
dag=dag)
#The tar file created can now be deleted from the raw folder
delete_tar_gz_files_op=python_operator.PythonOperator(
task_id='delete_tar_gz_files_'+job_desc,
python_callable=delete_tar_gz_files,
op_args=[file, process_date],
provide_context=False,
dag=dag)
def delete_tar_gz_files(file, process_date):
execution_command='gsutil rm ' + source_dir + '/' + file
print(execution_command)
returncode=os.system(execution_command)
if returncode != 0:
#logging.error("Halting process...")
exit(1)
手动运行状态: run status