本頁說明如何使用「多個資料表」來源,從 Microsoft SQL Server 資料庫讀取多個資料表。如要讓管道從多個資料表讀取資料,請使用多重資料表來源。如要讓管道讀取單一資料表,請參閱「讀取 SQL Server 資料表」一文。
多資料表來源會輸出包含多個結構描述的資料,並包含資料表名稱欄位,指出資料來源的資料表。使用多資料表來源時,請使用其中一個多資料表匯出來源,例如 BigQuery 多資料表或 GCS 多檔案。
事前準備
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Cloud Data Fusion, Cloud Storage, BigQuery, and Dataproc APIs.
- 建立 Cloud Data Fusion 執行個體。
- 請確認 SQL Server 資料庫可以接受 Cloud Data Fusion 的連線。為確保安全性,建議您建立私人 Cloud Data Fusion 執行個體。
在 Google Cloud 控制台中,前往 Cloud Data Fusion 頁面。
如要在 Cloud Data Fusion Studio 中開啟執行個體,請依序按一下「Instances」和「View instance」。
查看 Cloud Data Fusion 執行個體
使用 Cloud Data Fusion 時,您會同時使用 Google Cloud 主控台和獨立的 Cloud Data Fusion UI。您可以在 Google Cloud 主控台中建立 Google Cloud 專案,以及建立及刪除 Cloud Data Fusion 執行個體。在 Cloud Data Fusion UI 中,您可以使用各種頁面 (例如「Studio」或「Wrangler」) 使用 Cloud Data Fusion 功能。
將 SQL Server 密碼儲存為安全金鑰
將 SQL Server 密碼新增為安全金鑰,以便在 Cloud Data Fusion 執行個體上加密。在本指南的後續部分,您將確保使用 Cloud KMS 擷取密碼。
在任何 Cloud Data Fusion 頁面的右上角,按一下「系統管理員」。
按一下 [設定] 標籤。
按一下「Make HTTP Calls」。
在下拉式選單中,選擇「PUT」。
在路徑欄位中輸入
namespaces/NAMESPACE_ID/securekeys/PASSWORD
。在「Body」欄位中輸入
{"data":"SQL_SERVER_PASSWORD"}
。按一下 [傳送]。
請確認您收到的回應是狀態代碼 200
。
取得 SQL Server 適用的 JDBC 驅動程式
使用 Hub
在 Cloud Data Fusion UI 中,按一下「Hub」。
在搜尋列中輸入
Microsoft SQL Server JDBC Driver
。按一下「Microsoft SQL Server JDBC Driver」。
按一下「下載」。按照畫面上的步驟下載。
按一下「Deploy」。上傳上一個步驟中的 JAR 檔案。
按一下「完成」。
使用工作室
前往 Microsoft.com。
選擇要下載的內容,然後點選「下載」。
在 Cloud Data Fusion UI 中,按一下
「Menu」,然後前往「Studio」頁面。按一下
「新增」。在「Driver」下方,點選「Upload」。
上傳在步驟 2 下載的 JAR 檔案。
點按「Next」。
輸入名稱,即可設定驅動程式。
在「Class name」欄位中輸入
com.microsoft.sqlserver.jdbc.SQLServerDriver
。按一下「完成」。
部署多個資料表外掛程式
在 Cloud Data Fusion 網頁版 UI 中,按一下「Hub」。
在搜尋列中輸入
Multiple table plugins
。按一下「多個表格外掛程式」。
按一下 [Deploy] (部署)。
按一下「完成」。
按一下「建立管道」。
連線至 SQL Server
在 Cloud Data Fusion UI 中,按一下
「Menu」,然後前往「Studio」頁面。在「Studio」中,展開「Source」選單。
按一下「多個資料庫資料表」。
將游標懸停在「Multiple Database Tables」節點上,然後按一下「Properties」。
在「Reference name」欄位中,指定用於識別 SQL Server 來源的參照名稱。
在「JDBC 連線字串」欄位中輸入 JDBC 連線字串。例如:
jdbc:sqlserver://mydbhost:1433
。詳情請參閱「建立連結網址」。輸入 JDBC 外掛程式名稱、資料庫使用者名稱和 資料庫使用者密碼。
按一下「Validate」(驗證)。
點按
「Close」(關閉)。
連結至 BigQuery 或 Cloud Storage
在 Cloud Data Fusion UI 中,按一下
「Menu」,然後前往「Studio」頁面。展開「Sink」。
按一下「BigQuery 多資料表」或「GCS 多個檔案」。
將「Multiple Database Tables」節點連結至「BigQuery Multi Table」或「GCS Multi File」。
將游標懸停在「BigQuery 多重資料表」或「GCS 多重檔案」節點上,按一下「Properties」,然後設定接收端。
如需更多資訊,請參閱「Google BigQuery 多資料表接收端」和「Google Cloud Storage 多檔案接收端」。
按一下「Validate」(驗證)。
點按
「Close」(關閉)。
執行管道的預覽
在 Cloud Data Fusion UI 中,按一下
「Menu」,然後前往「Studio」頁面。按一下「預覽」。
按一下「執行」。等待預覽作業順利完成。
部署管道
在 Cloud Data Fusion UI 中,按一下
「Menu」,然後前往「Studio」頁面。按一下 [Deploy] (部署)。
執行管道
在 Cloud Data Fusion UI 中,按一下
「Menu」。按一下「清單」。
按一下管道。
在管道詳細資料頁面上,按一下「Run」。
後續步驟
- 進一步瞭解 Cloud Data Fusion。
- 請參考教學課程。