Google Cloud BigQuery 傳輸運算子至 MySQL¶
Google Cloud BigQuery 是 Google Cloud 的無伺服器資料倉儲服務。MySQL 是一個開源關聯式資料庫管理系統。此運算子可用於將資料從 BigQuery 表格複製到 MySQL。
先決條件任務¶
要使用這些運算子,您必須執行以下幾項操作
使用 Cloud Console 選擇或建立一個 Cloud Platform 專案。
為您的專案啟用計費功能,如 Google Cloud 文件 中所述。
啟用 API,如 Cloud Console 文件 中所述。
透過 pip 安裝 API 程式庫。
pip install 'apache-airflow[google]'詳細資訊請參閱 安裝。
運算子¶
將資料從一個 BigQuery 表格複製到另一個表格,是透過 BigQueryToMySqlOperator
運算子執行。
使用 Jinja 模板 以及 target_table_name
, impersonation_chain
, dataset_id
, table_id
, dataset_id
, table_id
來動態定義值。
您可以使用參數 selected_fields
來限制要複製的欄位(預設為所有欄位),以及參數 replace
來覆寫目的地表格而不是附加到它。 更多資訊,請參考以上連結。
傳輸資料¶
以下運算子將資料從 BigQuery 表格複製到 MySQL。
bigquery_to_mysql = BigQueryToMySqlOperator(
task_id="bigquery_to_mysql",
dataset_table=f"{DATASET_NAME}.{TABLE}",
target_table_name=destination_table,
replace=False,
)