追蹤 BigQuery 資料表的資料歷程
資料歷程 可讓您追蹤資料在系統中的移動方式,包括資料來源、傳遞至何處,以及套用的轉換。
瞭解如何開始追蹤 BigQuery 複製和查詢工作的資料沿襲:
從公開資料集複製兩個資料表。
new_york_taxi_trips
將兩個資料表的計程車趟次總數合併到新資料表。
查看這三項作業的沿襲關係視覺化圖表。
事前準備
設定專案:
- 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.
-
Enable the Dataplex Universal Catalog, BigQuery, and data lineage APIs.
-
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 Dataplex Universal Catalog, BigQuery, and data lineage APIs.
-
Dataplex Catalog 檢視者 (
roles/dataplex.catalogViewer
) Dataplex Universal Catalog 資源專案 -
資料沿襲檢視者 (
roles/datalineage.viewer
) 在您使用 BigQuery 的專案中 -
您使用 BigQuery 的專案中,BigQuery 資料檢視者 (
roles/bigquery.dataViewer
) 角色
必要的角色
如要取得查看沿襲關係圖所需的權限,請管理員授予下列 IAM 角色:
如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。
將公開資料集新增至專案
前往 Google Cloud 控制台的「BigQuery」頁面。
在「Explorer」窗格中,按一下「新增」。
在「新增」窗格中搜尋
Public datasets
,然後選取「公開資料集」結果。在「Marketplace」窗格中搜尋
NYC TLC Trips
,然後按一下「NYC TLC Trips」結果。按一下「查看資料集」。
這會將公開資料集的專案新增為參照,您可以在「Explorer」窗格中查看。詳細資料窗格會顯示「資料集資訊」,包括「資料集 ID」、「資料位置」和「上次修改」日期等資訊。
在專案中建立資料集
在「Explorer」窗格中,選取要建立資料集的專案。
按一下「動作」
,然後按一下「建立資料集」。在「Create dataset」(建立資料集) 頁面的「Dataset ID」(資料集 ID) 欄位中,輸入:
data_lineage_demo
。其他欄位則保留預設值。點選「建立資料集」。
在「Explorer」窗格中,按一下新加入的
data_lineage_demo
。
詳細資料窗格會顯示資料集的資訊。
將兩個可公開存取的資料表複製到資料集
開啟查詢編輯器:在詳細資料窗格中,按一下「
data_lineage_demo
」分頁旁的「 」(撰寫新查詢)。這個步驟會建立名為「Untitled
」的分頁。在查詢編輯器中輸入下列查詢,複製第一個表格。將
PROJECT_ID
替換為專案的 ID。CREATE TABLE `PROJECT_ID.data_lineage_demo.nyc_green_trips_2021` COPY `bigquery-public-data.new_york_taxi_trips.tlc_green_trips_2021`
按一下「執行」
。這個步驟會建立第一個資料表,稱為nyc_green_trips_2021
。在「查詢結果」窗格中,按一下「前往資料表」。這個步驟會顯示第一個表格的內容。
在查詢編輯器中,將先前的查詢替換成下列查詢,然後複製第二個資料表。將
PROJECT_ID
替換為專案的 ID。CREATE TABLE `PROJECT_ID.data_lineage_demo.nyc_green_trips_2022` COPY `bigquery-public-data.new_york_taxi_trips.tlc_green_trips_2022`
按一下「執行」
。這個步驟會建立第二個資料表,名為nyc_green_trips_2022
。在「查詢結果」窗格中,按一下「前往資料表」。這個步驟會顯示第二個表格的內容。
將資料匯總至新資料表
在查詢編輯器中輸入下列查詢。將
PROJECT_ID
替換為專案 ID。CREATE TABLE `PROJECT_ID.data_lineage_demo.total_green_trips_22_21` AS SELECT vendor_id, COUNT(*) AS number_of_trips FROM ( SELECT vendor_id FROM `PROJECT_ID.data_lineage_demo.nyc_green_trips_2022` UNION ALL SELECT vendor_id FROM `PROJECT_ID.data_lineage_demo.nyc_green_trips_2021` ) GROUP BY vendor_id
按一下「執行」
。這個步驟會建立名為total_green_trips_22_21
的合併資料表。在「查詢結果」窗格中,按一下「前往資料表」。這個步驟會顯示合併後的表格。
在 Dataplex Universal Catalog 中查看歷程圖
在 Google Cloud 控制台中,前往 Dataplex Universal Catalog 的「Search」(搜尋) 頁面。
在「選擇搜尋平台」中,選取「Dataplex Catalog」做為搜尋模式。
在「搜尋」方塊中輸入
total_green_trips_22_21
,然後按一下「搜尋」。在結果清單中,按一下
total_green_trips_22_21
。這個步驟會顯示 BigQuery 資料表的「詳細資料」分頁。按一下「沿革」分頁標籤。

在沿襲圖中,每個矩形節點都代表一個資料表,可能是原始、複製或合併的資料表。您可以執行以下操作:
如要顯示或隱藏表格來源,請按一下「+」(展開) 或「-」(收合)。
如要顯示表格資訊,請按一下節點。這個步驟會顯示節點「詳細資料」窗格。
如要顯示程序資訊,請按一下
。這個步驟會顯示「詳細資料」窗格,當中會顯示將來源資料表轉換為目標資料表的工作。

清除所用資源
如要避免系統向您的 Google Cloud 帳戶收取本頁所用資源的費用,請按照下列步驟操作。
刪除專案
- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
刪除資料集
前往 Google Cloud 控制台的「BigQuery」頁面。
在「Explorer」窗格中,搜尋您建立的
data_lineage_demo
資料集。在資料集上按一下滑鼠右鍵,然後選取「刪除」。
確認刪除動作。
後續步驟
- 進一步瞭解資料歷程。
- 瞭解如何執行 BigQuery 查詢。
- 瞭解如何使用資料沿襲。
- 瞭解 Dataplex Universal Catalog 定價。