首页 > 解决方案 > bigquery_operator 不允许覆盖 GCP Airflow 1.10.15 上的默认参数

问题描述

我正在尝试使用 将 BQ 表导出到 GCS airflow.contrib.operators.bigquery_operator,但是我需要自定义分隔符并且没有标题。当我更改设置时,这对结果表没有影响。我究竟做错了什么?

    export_to_gcs_op = BigQueryToCloudStorageOperator(
        task_id=f'bq_transfer_{TABLE}_to_gcs',
        source_project_dataset_table=f'{PROJECT_ID}.{DATASET}.{TABLE}',
        export_format='csv',
        field_delimiter='',
        print_header=False,
        destination_cloud_storage_uris=[f"gs://{GCS_BUCKET}/{TABLE}.csv"],
    )

我公司设置的气流版本,我无法升级它:

apache-airflow = "1.10.15"
apache-airflow-backport-providers-google = "2021.3.3"

标签: google-cloud-platformgoogle-cloud-storageairflow

解决方案


我认为你需要export_format='CSV'大写。它也是默认值,因此您可以根据需要省略此字段。

来自https://github.com/apache/airflow/blob/1.10.15/airflow/contrib/hooks/bigquery_hook.py#L976-L981

if export_format == 'CSV':
    # Only set fieldDelimiter and printHeader fields if using CSV.
    # Google does not like it if you set these fields for other export
    # formats.
    configuration['extract']['fieldDelimiter'] = field_delimiter
    configuration['extract']['printHeader'] = print_header

推荐阅读