追蹤 BigQuery 資料表的資料歷程

資料歷程 可讓您追蹤資料在系統中的移動方式,包括資料來源、傳遞至何處,以及套用的轉換。

瞭解如何開始追蹤 BigQuery 複製和查詢工作的資料沿襲:

  1. 從公開資料集複製兩個資料表。new_york_taxi_trips

  2. 將兩個資料表的計程車趟次總數合併到新資料表。

  3. 查看這三項作業的沿襲關係視覺化圖表。

事前準備

設定專案:

  1. 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.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Enable the Dataplex Universal Catalog, BigQuery, and data lineage APIs.

    Enable the APIs

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Make sure that billing is enabled for your Google Cloud project.

  7. Enable the Dataplex Universal Catalog, BigQuery, and data lineage APIs.

    Enable the APIs

  8. 必要的角色

    如要取得查看沿襲關係圖所需的權限,請管理員授予下列 IAM 角色:

    如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。

    您或許還可透過自訂角色或其他預先定義的角色取得必要權限。

將公開資料集新增至專案

  1. 前往 Google Cloud 控制台的「BigQuery」頁面。

    前往 BigQuery

  2. 在「Explorer」窗格中,按一下「新增」

  3. 在「新增」窗格中搜尋 Public datasets,然後選取「公開資料集」結果。

  4. 在「Marketplace」窗格中搜尋 NYC TLC Trips,然後按一下「NYC TLC Trips」結果。

  5. 按一下「查看資料集」

這會將公開資料集的專案新增為參照,您可以在「Explorer」窗格中查看。詳細資料窗格會顯示「資料集資訊」,包括「資料集 ID」、「資料位置」和「上次修改」日期等資訊。

在專案中建立資料集

  1. 在「Explorer」窗格中,選取要建立資料集的專案。

  2. 按一下「動作」,然後按一下「建立資料集」

  3. 在「Create dataset」(建立資料集) 頁面的「Dataset ID」(資料集 ID) 欄位中,輸入: data_lineage_demo。其他欄位則保留預設值。

  4. 點選「建立資料集」

  5. 在「Explorer」窗格中,按一下新加入的 data_lineage_demo

詳細資料窗格會顯示資料集的資訊

將兩個可公開存取的資料表複製到資料集

  1. 開啟查詢編輯器:在詳細資料窗格中,按一下「data_lineage_demo」分頁旁的「」(撰寫新查詢)。這個步驟會建立名為「Untitled」的分頁。

  2. 在查詢編輯器中輸入下列查詢,複製第一個表格。將 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`
    
  3. 按一下「執行」。這個步驟會建立第一個資料表,稱為 nyc_green_trips_2021

  4. 在「查詢結果」窗格中,按一下「前往資料表」。這個步驟會顯示第一個表格的內容。

  5. 在查詢編輯器中,將先前的查詢替換成下列查詢,然後複製第二個資料表。將 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`
    
  6. 按一下「執行」。這個步驟會建立第二個資料表,名為 nyc_green_trips_2022

  7. 在「查詢結果」窗格中,按一下「前往資料表」。這個步驟會顯示第二個表格的內容。

將資料匯總至新資料表

  1. 在查詢編輯器中輸入下列查詢。將 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
    
  2. 按一下「執行」。這個步驟會建立名為 total_green_trips_22_21 的合併資料表。

  3. 在「查詢結果」窗格中,按一下「前往資料表」。這個步驟會顯示合併後的表格。

在 Dataplex Universal Catalog 中查看歷程圖

  1. 在 Google Cloud 控制台中,前往 Dataplex Universal Catalog 的「Search」(搜尋) 頁面。

    前往「搜尋」頁面

  2. 在「選擇搜尋平台」中,選取「Dataplex Catalog」做為搜尋模式。

  3. 在「搜尋」方塊中輸入 total_green_trips_22_21,然後按一下「搜尋」

  4. 在結果清單中,按一下 total_green_trips_22_21。這個步驟會顯示 BigQuery 資料表的「詳細資料」分頁。

  5. 按一下「沿革」分頁標籤。

「total_green_trips_22_21」表格,詳細資料面板固定在底部。
圖 1. 追蹤資料歷程並查看節點詳細資料

在沿襲圖中,每個矩形節點都代表一個資料表,可能是原始、複製或合併的資料表。您可以執行以下操作:

  • 如要顯示或隱藏表格來源,請按一下「+」(展開) 或「-」(收合)

  • 如要顯示表格資訊,請按一下節點。這個步驟會顯示節點「詳細資料」窗格。

  • 如要顯示程序資訊,請按一下 查看沿襲程序詳細資料。這個步驟會顯示「詳細資料」窗格,當中會顯示將來源資料表轉換為目標資料表的工作。

中間的 nyc_green_trips_2021 表格,詳細資料面板固定在底部。
圖 2. 資料歷程 (含程序詳細資料)

清除所用資源

如要避免系統向您的 Google Cloud 帳戶收取本頁所用資源的費用,請按照下列步驟操作。

刪除專案

  1. In the Google Cloud console, go to the Manage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

刪除資料集

  1. 前往 Google Cloud 控制台的「BigQuery」頁面。

    前往 BigQuery

  2. 在「Explorer」窗格中,搜尋您建立的 data_lineage_demo 資料集。

  3. 在資料集上按一下滑鼠右鍵,然後選取「刪除」

  4. 確認刪除動作。

後續步驟