【问题标题】:bigquery_operator does not allow to override default parameters on GCP Airflow 1.10.15bigquery_operator 不允许覆盖 GCP Airflow 1.10.15 上的默认参数
【发布时间】:2021-11-05 01:41:44
【问题描述】:

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

    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-platform google-cloud-storage airflow


    【解决方案1】:

    我认为您需要大写的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
    

    【讨论】:

    • @MStikh - 这能解决你的问题吗?
    • 不,这不起作用,这就是为什么我的问题是..
    • @MStikh 您发布的代码有csv 小写,请确保使用CSV 大写。
    猜你喜欢
    • 2013-02-03
    • 2012-09-09
    • 1970-01-01
    • 2022-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多