Google Cloud BigQuery 傳輸運算子至 Google Cloud Storage¶
Google Cloud BigQuery 是 Google Cloud 的無伺服器資料倉儲服務。Google Cloud Storage (GCS) 是一種用於儲存非結構化資料的託管服務。此運算子可用於將資料從 BigQuery 表格匯出到 Cloud Storage 儲存桶中的檔案。
先決條件任務¶
要使用這些運算子,您必須執行以下幾項操作
使用 Cloud Console 選擇或建立一個 Cloud Platform 專案。
為您的專案啟用計費功能,如 Google Cloud 文件中所述。
啟用 API,如 Cloud Console 文件中所述。
透過 pip 安裝 API 程式庫。
pip install 'apache-airflow[google]'詳細資訊請參閱安裝。
運算子¶
從 BigQuery 匯出表格到 GCS 是透過 BigQueryToGCSOperator
運算子執行。
使用 Jinja 模板 與 source_project_dataset_table
, destination_cloud_storage_uris
, export_format
, labels
, impersonation_chain
, job_id
來動態定義值。
您可以定義多個目標 URI,以及其他設定,例如 compression
和 export_format
。有關更多資訊,請參閱上面的連結。
匯出表格¶
以下運算子將 BigQuery 表格匯出到 GCS。
bigquery_to_gcs = BigQueryToGCSOperator(
task_id="bigquery_to_gcs",
source_project_dataset_table=f"{DATASET_NAME}.{TABLE}",
destination_cloud_storage_uris=[f"gs://{BUCKET_NAME}/{BUCKET_FILE}"],
)