【问题标题】:How to specify a BigQuery table as an input source for the AutoMLImportDataOperator Airflow Operator?如何将 BigQuery 表指定为 AutoMLImportDataOperator Airflow Operator 的输入源?
【发布时间】:2020-03-25 13:51:51
【问题描述】:

根据 Airflow Docs here 中提供的文档,可以将 GCS 配置为 AutoMLImportDataOperator 的输入源。但是,我很好奇如何使用 BQ 表,因为 AutoML Tables 本身就有它的功能。任何建议将不胜感激。

【问题讨论】:

    标签: google-cloud-platform airflow google-cloud-automl automl


    【解决方案1】:

    AutoML Tables supports BigQuery 和 GCS 作为源。您可以使用 BigQuery URI 格式指定训练数据的位置,并且必须符合以下格式:bq://<project_id>.<dataset_id>.<table_id>

    在 Airflow DAG 中,您可以使用 AutoMLImportDataOperatorinput_config,如下所示

    IMPORT_INPUT_CONFIG = {"bigquery_source": {"input_uri": 'bq://{}.{}.{}'.format(project_id, bq_dataset, bq_table)}}
    
    import_dataset_task = AutoMLImportDataOperator(
            task_id="import_dataset_task",
            dataset_id=dataset_id,
            location=GCP_AUTOML_LOCATION,
            input_config=IMPORT_INPUT_CONFIG,
    )
    

    您可以参考 Airflow 示例 DAG here 以获取以 GCS 作为源的更完整示例。您必须使用 BigQiuery URI 更新 IMPORT_INPUT_CONFIG 变量。

    【讨论】:

      【解决方案2】:

      目前 GCP 中的 Airflow 仍处于预发布版 [0] 中,据我了解,到目前为止,Airflow 运营商 [1] 中还没有此功能。您可以使用 bigquery_to_gcs [2] 运算符将 BQ 数据移动到 GCS 中,以便以后使用 AutoMLImportDataOperator。或者,您可以尝试创建自定义运算符 [3]

      [0]https://cloud.google.com/automl-tables/docs/integrations

      [1]https://airflow.readthedocs.io/en/latest/howto/operator/gcp/automl.html

      [2]https://airflow.apache.org/docs/stable/_modules/airflow/contrib/operators/bigquery_to_gcs.html

      [3]https://airflow.readthedocs.io/en/latest/howto/custom-operator.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-04-05
        • 1970-01-01
        • 2012-08-23
        • 1970-01-01
        • 2022-11-18
        • 2018-07-30
        • 2021-11-02
        • 1970-01-01
        相关资源
        最近更新 更多