Google Cloud Storage 到 Google Sheets 傳輸運算子¶
Google 提供一項服務 Google Cloud Storage。這項服務用於儲存來自各種應用程式的大資料。
藉助 Google Sheets,每個人都可以同時在同一個電子表格上協作。使用公式、函式和格式選項來節省時間並簡化常見的電子表格任務。
先決任務¶
要使用這些運算子,您需要執行以下幾項操作:
使用 Cloud Console 選擇或建立一個 Cloud Platform 專案。
為您的專案啟用計費,如 Google Cloud 文件中所述。
啟用 API,如 Cloud Console 文件中所述。
透過 pip 安裝 API 庫。
pip install 'apache-airflow[google]'有關 Installation 的詳細資訊請參見此處。
將資料從 GCS 上傳到 Google Sheets¶
要將資料從 Google Cloud Storage 上傳到 Google Spreadsheet,您可以使用 GCSToGoogleSheetsOperator。
tests/system/google/cloud/gcs/example_gcs_to_sheets.py
upload_gcs_to_sheet = GCSToGoogleSheetsOperator(
task_id="upload_gcs_to_sheet",
bucket_name=BUCKET_NAME,
object_name="{{ task_instance.xcom_pull('upload_sheet_to_gcs')[0] }}",
spreadsheet_id="{{ task_instance.xcom_pull(task_ids='create_spreadsheet', key='spreadsheet_id') }}",
gcp_conn_id=CONNECTION_ID,
)
您可以將 Jinja templating 與 spreadsheet_id, bucket_name, object_name, spreadsheet_range, impersonation_chain 結合使用。