Google Cloud Storage 至 Google Sheets 傳輸運算子¶
Google 提供一項服務 Google Cloud Storage。此服務用於儲存來自各種應用程式的大型資料。
透過 Google Sheets,所有人都可以同時在同一個試算表中協作。使用公式、函數和格式設定選項,以節省時間並簡化常見的試算表任務。
先決條件任務¶
若要使用這些運算子,您必須完成幾件事
使用 Cloud Console 選取或建立 Cloud Platform 專案。
如 Google Cloud 文件中所述,為您的專案啟用計費功能。
如 Cloud Console 文件中所述,啟用 API。
透過 pip 安裝 API 程式庫。
pip install 'apache-airflow[google]'如需詳細資訊,請參閱安裝。
從 GCS 上傳資料至 Google Sheets¶
若要從 Google Cloud Storage 上傳資料至 Google 試算表,您可以使用 GCSToGoogleSheetsOperator
。
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 範本 與 spreadsheet_id
、bucket_name
、object_name
、spreadsheet_range
、impersonation_chain
搭配使用。