使用自動資料品質

本文說明如何使用 Dataplex Universal Catalog 資料品質掃描作業,評估、監控及管理資料品質。資料品質掃描可協助您自動驗證資料的完整性、有效性和一致性。

透過資料品質掃描,您可以定義規則來檢查遺漏值、確保值符合規則運算式或屬於一組值、驗證唯一性,或使用自訂 SQL 進行更複雜的驗證,例如異常偵測。本文說明如何建立及管理資料品質掃描作業。

如要進一步瞭解資料品質掃描作業,請參閱「關於自動資料品質」。

事前準備

  1. Enable the Dataplex API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  2. 選用:如要讓 Dataplex Universal Catalog 根據資料剖析掃描結果產生資料品質規則建議,請建立並執行資料剖析掃描

必要的角色

  • 如要對 BigQuery 資料表執行資料品質掃描,您需要有權讀取 BigQuery 資料表,以及在用於掃描資料表的專案中建立 BigQuery 工作的權限。

  • 如果 BigQuery 資料表和資料品質掃描位於不同專案,您需要為包含資料品質掃描的專案,授予對應 BigQuery 資料表的讀取權限。

  • 如果資料品質規則參照其他資料表,掃描專案的服務帳戶必須對這些資料表擁有讀取權限。

  • 如要取得將掃描結果匯出至 BigQuery 資料表所需的權限,請要求管理員在結果資料集和資料表中,授予 Dataplex Universal Catalog 服務帳戶 BigQuery 資料編輯者 (roles/bigquery.dataEditor) IAM 角色。這會授予下列權限:

    • bigquery.datasets.get
    • bigquery.tables.create
    • bigquery.tables.get
    • bigquery.tables.getData
    • bigquery.tables.update
    • bigquery.tables.updateData
  • 如果 BigQuery 資料是透過 Dataplex Universal Catalog 湖泊整理,請授予 Dataplex Universal Catalog 服務帳戶 Dataplex Metadata Reader (roles/dataplex.metadataReader) 和 Dataplex Viewer (roles/dataplex.viewer) IAM 角色。或者,您需要下列所有權限:

    • dataplex.lakes.list
    • dataplex.lakes.get
    • dataplex.zones.list
    • dataplex.zones.get
    • dataplex.entities.list
    • dataplex.entities.get
    • dataplex.operations.get
  • 如要掃描 Cloud Storage 中的 BigQuery 外部資料表,請將 bucket 的「Storage 物件檢視者」角色 (roles/storage.objectViewer) 授予 Dataplex Universal Catalog 服務帳戶。或者,您也可以將下列權限指派給 Dataplex Universal Catalog 服務帳戶:

    • storage.buckets.get
    • storage.objects.get
  • 如要將資料品質掃描結果發布為 Dataplex Universal Catalog 中繼資料,您必須取得資料表的 BigQuery 資料編輯者 (roles/bigquery.dataEditor) IAM 角色,以及資料表所在位置的 @bigquery 項目群組 dataplex.entryGroups.useDataQualityScorecardAspect 權限。或者,您必須在與資料表相同位置的 @bigquery 項目群組中,獲派 Dataplex Catalog 編輯者 (roles/dataplex.catalogEditor) 角色。

    或者,您需要下列所有權限:

    • bigquery.tables.update - 桌上
    • dataplex.entryGroups.useDataQualityScorecardAspect - 項目群組的 @bigquery

    或者,您需要下列所有權限:

    • dataplex.entries.update - @bigquery 項目群組
    • dataplex.entryGroups.useDataQualityScorecardAspect - 項目群組的 @bigquery
  • 如要存取受 BigQuery 資料欄層級存取權政策保護的資料欄,請為這些資料欄指派 Dataplex Universal Catalog 服務帳戶權限。建立或更新資料掃描作業的使用者也需要欄的權限。

  • 如果資料表已啟用 BigQuery 資料列層級存取權政策,您只能掃描 Dataplex Universal Catalog 服務帳戶可見的資料列。請注意,系統不會評估個別使用者的存取權限是否符合資料列層級政策。

必要的資料掃描角色

如要使用自動資料品質功能,請要求管理員授予下列其中一種 IAM 角色:

  • DataScan 資源的完整存取權:Dataplex DataScan 管理員 (roles/dataplex.dataScanAdmin)
  • 如要建立 DataScan 資源:專案的 Dataplex DataScan 建立者 (roles/dataplex.dataScanCreator)
  • DataScan 資源的寫入權限:Dataplex DataScan 編輯者 (roles/dataplex.dataScanEditor)
  • 具備 DataScan 資源的讀取權限,規則和結果除外: Dataplex DataScan 檢視者 (roles/dataplex.dataScanViewer)
  • 具備 DataScan 資源的讀取權限,包括規則和結果: Dataplex DataScan 資料檢視者 (roles/dataplex.dataScanDataViewer)

下表列出 DataScan 權限:

權限名稱 授予下列權限:
dataplex.datascans.create 建立 DataScan
dataplex.datascans.delete 刪除 DataScan
dataplex.datascans.get 查看 ID 或時間表等作業中繼資料,但不包括結果和規則
dataplex.datascans.getData 查看 DataScan 詳細資料,包括規則和結果
dataplex.datascans.list 清單 DataScan
dataplex.datascans.run 執行 DataScan
dataplex.datascans.update 更新 DataScan 的說明
dataplex.datascans.getIamPolicy 查看掃描作業目前的 IAM 權限
dataplex.datascans.setIamPolicy 設定掃描作業的 IAM 權限

定義資料品質規則

您可以使用內建規則自訂 SQL 檢查定義資料品質規則。如果您使用 Google Cloud CLI,可以在 JSON 或 YAML 檔案中定義這些規則。

以下各節的範例說明如何定義各種資料品質規則。這些規則會驗證含有顧客交易資料的範例資料表。假設資料表具有下列結構定義:

資料欄名稱 欄類型 資料欄說明
transaction_timestamp 時間戳記 交易的時間戳記。資料表會依這個欄位進行分區。
customer_id String 客戶 ID 格式為 8 個字母,後接 16 位數字。
transaction_id String 交易 ID 在資料表中不得重複。
currency_id String 支援的幣別之一。幣別類型必須與維度表 dim_currency 中的可用幣別之一相符。
金額 浮點值 交易金額。
discount_pct 浮點值 折扣百分比。這個值必須介於 0 到 100 之間。

使用內建規則類型定義資料品質規則

下列範例規則是以內建規則類型為準。您可以使用 Google Cloud 控制台或 API,根據內建規則類型建立規則。Dataplex Universal Catalog 可能會建議部分規則。

資料欄名稱 規則類型 建議的尺寸 規則參數
transaction_id 唯一性檢查 唯一性 門檻:Not Applicable
amount 空值檢查 完整性 門檻:100%
customer_id 規則運算式檢查 有效性 規則運算式:^[0-9]{8}[a-zA-Z]{16}$
門檻:100%
currency_id 值設定檢查 有效性 設定:USD,JPY,INR,GBP,CAN
門檻:100%

使用自訂 SQL 規則定義資料品質規則

如要建構自訂 SQL 規則,請使用下列架構:

  • 建立一次評估一個資料列的規則時,請建立運算式,在 Dataplex Universal Catalog 評估查詢 SELECT COUNTIF(CUSTOM_SQL_EXPRESSION) FROM TABLE 時,產生成功資料列的數量。Dataplex Universal Catalog 會根據門檻檢查成功列的數量。

  • 建立規則時,如果需要評估資料列或使用資料表條件,請建立運算式,讓 Dataplex Universal Catalog 評估查詢 SELECT IF(CUSTOM_SQL_EXPRESSION) FROM TABLE 時傳回成功或失敗。

  • 建立規則來評估資料集的無效狀態時,請提供會傳回無效資料列的陳述式。如果傳回任何資料列,即代表這項規則失敗。省略 SQL 陳述式結尾的分號。

  • 您可以在規則中使用資料參照參數 ${data()},參照資料來源表格及其所有前提條件篩選器,而不必明確提及來源表格及其篩選器。前置條件篩選器的範例包括資料列篩選器、取樣百分比和遞增篩選器。${data()} 參數會區分大小寫。

下列範例規則是以自訂 SQL 規則為準。

規則類型 規則說明 SQL 運算式
資料列條件 檢查 discount_pct 的值是否介於 0 到 100 之間。 0 <discount_pct AND discount_pct < 100
資料列條件 參考檢查,確認 currency_id 是支援的貨幣之一。 currency_id in (select id from my_project_id.dim_dataset.dim_currency)
資料表條件 匯總 SQL 運算式,用於檢查平均 discount_pct 是否介於 30% 到 50% 之間。 30<avg(discount) AND avg(discount) <50
資料列條件 檢查日期是否為未來的日期。 TIMESTAMP(transaction_timestamp) < CURRENT_TIMESTAMP()
資料表條件 BigQuery 使用者定義函式 (UDF),可檢查每個國家/地區的平均交易金額是否低於預先定義的值。執行下列指令,建立 (JavaScript) UDF:
        CREATE OR REPLACE FUNCTION
        myProject.myDataset.average_by_country (
          country STRING, average FLOAT64)
        RETURNS BOOL LANGUAGE js AS R"""
        if (country = "CAN" && average < 5000){
          return 1
        } else if (country = "IND" && average < 1000){
          return 1
        } else { return 0 }
        """;
       
以下是檢查 country=CAN 平均交易金額的規則範例:
        myProject.myDataset.average_by_country(
        "CAN",
        (SELECT avg(amount) FROM
          myProject.myDataset.transactions_table
            WHERE currency_id = 'CAN'
        ))
      
資料表條件 BigQuery ML discount_pct 中的 discount_pct 預測子句,用於識別異常狀況。系統會根據 customercurrencytransaction 檢查是否應套用折扣。這項規則會檢查預測值是否與實際值相符,至少 99% 的時間都必須相符。假設:機器學習模型是在使用規則前建立。使用下列指令建立機器學習模型:
  CREATE MODEL
  model-project-id.dataset-id.model-name
        OPTIONS(model_type='logistic_reg') AS
  SELECT
  IF(discount_pct IS NULL, 0, 1) AS label,
  IFNULL(customer_id, "") AS customer,
  IFNULL(currency_id, "") AS currency,
  IFNULL(amount, 0.0) AS amount
  FROM
  `data-project-id.dataset-id.table-names`
  WHERE transaction_timestamp < '2022-01-01';
  
下列規則會檢查預測準確率是否大於 99%。
      SELECT
        accuracy > 0.99
      FROM
       ML.EVALUATE
        (MODEL model-project-id.dataset-id.model-name,
         (
          SELECT
            customer_id,
            currency_id,
            amount,
            discount_pct
          FROM
            data-project-id.dataset-id.table-names
          WHERE transaction_timestamp > '2022-01-01';
         )
        )
    
資料列條件 BigQuery ML 預測函式,用於識別 discount_pct 中的異常狀況。函式會根據 customercurrencytransaction 檢查是否應套用折扣。這項規則會找出所有預測結果不符的情況。 假設:機器學習模型是在使用規則前建立。使用下列指令建立 ML 模型:
  CREATE MODEL
  model-project-id.dataset-id.model-name
        OPTIONS(model_type='logistic_reg') AS
  SELECT
  IF(discount_pct IS NULL, 0, 1) AS label,
  IFNULL(customer_id, "") AS customer,
  IFNULL(currency_id, "") AS currency,
  IFNULL(amount, 0.0) AS amount
  FROM
  `data-project-id.dataset-id.table-names`
  WHERE transaction_timestamp < '2022-01-01';
  
下列規則會檢查每列的折扣預測是否與實際折扣相符。
       IF(discount_pct > 0, 1, 0)
          =(SELECT predicted_label FROM
           ML.PREDICT(
            MODEL model-project-id.dataset-id.model-name,
              (
                SELECT
                  customer_id,
                  currency_id,
                  amount,
                  discount_pct
                FROM
                  data-project-id.dataset-id.table-names AS t
                    WHERE t.transaction_timestamp =
                     transaction_timestamp
                   LIMIT 1
              )
            )
         )
    
SQL 斷言 檢查是否有任何資料列的折扣百分比小於或等於 30,藉此驗證今天的 discount_pct 是否大於 30%。 SELECT * FROM my_project_id.dim_dataset.dim_currency WHERE discount_pct <= 30 AND transaction_timestamp >= current_date()
SQL 斷言 (含資料參照參數)

檢查所有支援的貨幣,今天的 discount_pct 是否大於 30%。

日期篩選器 transaction_timestamp >= current_date() 會套用為資料來源表格的資料列篩選器。

資料參照參數 ${data()} 會做為 my_project_id.dim_dataset.dim_currency WHERE transaction_timestamp >= current_date() 的預留位置,並套用列篩選器。

SELECT * FROM ${data()} WHERE discount_pct > 30

使用 gcloud CLI 定義資料品質規則

以下 YAML 檔案範例使用的部分規則,與使用內建型別的規則範例自訂 SQL 規則範例相同。這個 YAML 檔案也包含資料品質掃描的其他規格,例如篩選器和取樣百分比。使用 gcloud CLI 建立或更新資料品質掃描時,您可以將類似這樣的 YAML 檔案做為 --data-quality-spec-file 引數的輸入內容。

rules:
- uniquenessExpectation: {}
  column: transaction_id
  dimension: UNIQUENESS
- nonNullExpectation: {}
  column: amount
  dimension: COMPLETENESS
  threshold: 1
- regexExpectation:
    regex: '^[0-9]{8}[a-zA-Z]{16}$'
  column : customer_id
  ignoreNull : true
  dimension : VALIDITY
  threshold : 1
- setExpectation :
    values :
    - 'USD'
    - 'JPY'
    - 'INR'
    - 'GBP'
    - 'CAN'
  column : currency_id
  ignoreNull : true
  dimension : VALIDITY
  threshold : 1
- rangeExpectation:
    minValue : '0'
    maxValue : '100'
  column : discount_pct
  ignoreNull : true
  dimension : VALIDITY
  threshold : 1
- rowConditionExpectation:
    sqlExpression : 0 < `discount_pct` AND `discount_pct` < 100
  column: discount_pct
  dimension: VALIDITY
  threshold: 1
- rowConditionExpectation:
    sqlExpression : currency_id in (select id from `my_project_id.dim_dataset.dim_currency`)
  column: currency_id
  dimension: VALIDITY
  threshold: 1
- tableConditionExpectation:
    sqlExpression : 30 < avg(discount_pct) AND avg(discount_pct) < 50
  dimension: VALIDITY
- rowConditionExpectation:
    sqlExpression : TIMESTAMP(transaction_timestamp) < CURRENT_TIMESTAMP()
  column: transaction_timestamp
  dimension: VALIDITY
  threshold: 1
- sqlAssertion:
    sqlStatement : SELECT * FROM `my_project_id.dim_dataset.dim_currency` WHERE discount_pct > 100
  dimension: VALIDITY
samplingPercent: 50
rowFilter: discount_pct > 100
postScanActions:
  bigqueryExport:
    resultsTable: projects/my_project_id/datasets/dim_dataset/tables/dim_currency
  notificationReport:
    recipients:
      emails:
      - '222larabrown@gmail.com'
      - 'cloudysanfrancisco@gmail.com'
    scoreThresholdTrigger:
      scoreThreshold: 50
    jobFailureTrigger: {}
    jobEndTrigger: {}
catalogPublishingEnabled: true

建立資料品質掃描作業

控制台

  1. 在 Google Cloud 控制台,前往 Dataplex Universal Catalog 的「資料剖析與品質」頁面。

    前往「Data profiling & quality」(資料剖析與品質) 頁面

  2. 按一下「建立資料品質掃描作業」

  3. 在「定義掃描」視窗中,填入下列欄位:

    1. 選用:輸入「顯示名稱」

    2. 輸入 ID。請參閱資源命名慣例

    3. 選用:輸入說明

    4. 在「Table」(資料表) 欄位中,按一下「Browse」(瀏覽)。選擇要掃描的資料表,然後按一下「選取」。 系統僅支援標準 BigQuery 資料表。

      如為多區域資料集內的資料表,請選擇要建立資料掃描的區域。

      如要瀏覽 Dataplex Universal Catalog 湖泊中整理的資料表,請按一下「Browse within Dataplex Lakes」(在 Dataplex 湖泊中瀏覽)

    5. 在「範圍」欄位中,選擇「增量」或「完整資料」

      • 如果選擇「增量」:在「時間戳記欄」欄位中,從 BigQuery 資料表選取 DATETIMESTAMP 類型的資料欄,這類資料欄的值會隨著新增記錄而增加,並能用來識別新的記錄。或者,您也可以選取用來將資料表分區的資料欄。
    6. 如要篩選資料,請選取「篩選列」核取方塊。提供由有效 SQL 運算式組成的資料列篩選器,該運算式可用於 GoogleSQL 語法的 WHERE 子句。例如:col1 >= 0。篩選器可由多個資料欄條件組合而成。例如:col1 >= 0 AND col2 < 10

    7. 如要對資料取樣,請在「取樣大小」清單中選取取樣百分比。請選擇介於 0.0% 至 100.0% 之間的百分比值,最多可有 3 位小數。如果是較大的資料集,請選擇較低的取樣百分比。舉例來說,如果資料表大小為 1 PB,且您輸入的值介於 0.1% 到 1.0% 之間,資料品質掃描就會取樣 1 到 10 TB 的資料。如果是增量資料掃描,資料品質掃描會對最新增量套用取樣。

    8. 如要將資料品質掃描結果發布為 Dataplex Universal Catalog 中繼資料,請選取「將結果發布至 Dataplex Catalog」核取方塊。

      您可以在來源資料表的 BigQuery 和 Dataplex Universal Catalog 頁面中,查看「資料品質」分頁的最新掃描結果。如要讓使用者存取已發布的掃描結果,請參閱本文的「授予資料品質掃描結果的存取權」一節。

    9. 在「時間表」部分,選擇下列其中一個選項:

      • 重複:依排程執行資料品質掃描,包括每小時、每天、每週、每月或自訂。指定掃描的執行頻率和時間。如果選擇自訂,請使用 cron 格式指定時間表。

      • 隨選:視需要執行資料品質掃描作業。

      • 單次:立即執行一次資料品質掃描,並在存留時間結束後移除掃描作業。

      • 存留時間:存留時間值是指掃描執行到刪除之間的時間間隔。如果資料品質掃描未指定存留時間,系統會在執行後 24 小時自動刪除。生命週期可介於 0 秒 (立即刪除) 到 365 天。

    10. 按一下「繼續」

  4. 在「資料品質規則」視窗中,定義要為這項資料品質掃描設定的規則。

    1. 按一下「新增規則」,然後選擇下列任一做法。

      • 以資料概況為基礎的建議:根據現有的資料剖析掃描結果,從建議中建立規則。

        1. 選擇資料欄:選取要取得建議規則的資料欄。

        2. 選擇掃描專案:如果資料剖析掃描作業所在的專案,與您建立資料品質掃描作業的專案不同,請選取要從哪個專案提取剖析掃描作業。

        3. 選擇資料概況結果:選取一或多個資料概況結果,然後按一下「確定」。系統會根據這些資訊產生建議規則清單,供您做為起點。

        4. 找出要新增的規則,勾選旁邊的核取方塊,然後按一下「選取」。選取後,規則會新增至目前的規則清單。接著即可編輯規則。

      • 內建規則類型:根據預先定義的規則建立規則。 請參閱預先定義的規則清單。

        1. 選擇資料欄:選取要套用規則的資料欄。

        2. 選擇規則類型:選取要選擇的規則類型,然後按一下「確定」。顯示的規則類型取決於您選取的資料欄。

        3. 找出要新增的規則,勾選旁邊的核取方塊,然後按一下「選取」。選取後,規則會新增至目前的規則清單。接著即可編輯規則。

      • SQL 資料列檢查規則:建立要套用至每個資料列的自訂 SQL 規則。

        1. 在「維度」中,選擇一個維度。

        2. 在「通過門檻」中,選擇必須通過檢查的記錄百分比。

        3. 在「欄名稱」中選擇資料欄。

        4. 在「提供 SQL 運算式」欄位中,輸入評估布林值 true (通過) 或 false (失敗) 的 SQL 運算式。詳情請參閱「支援的自訂 SQL 規則類型」和「定義資料品質規則」中的範例。

        5. 按一下 [新增]。

      • SQL 匯總檢查規則:建立自訂 SQL 資料表條件規則。

        1. 在「維度」中,選擇一個維度。

        2. 在「欄名稱」中選擇資料欄。

        3. 在「提供 SQL 運算式」欄位中,輸入評估布林值 true (通過) 或 false (失敗) 的 SQL 運算式。詳情請參閱「支援的自訂 SQL 規則類型」和「定義資料品質規則」中的範例。

        4. 按一下 [新增]。

      • SQL 斷言規則:建立自訂 SQL 斷言規則,檢查資料是否處於無效狀態。

        1. 在「維度」中,選擇一個維度。

        2. 選用:在「欄名稱」中選擇欄。

        3. 在「Provide a SQL statement」(提供 SQL 陳述式) 欄位中,輸入會傳回符合無效狀態資料列的 SQL 陳述式。如果傳回任何資料列,即代表這項規則失敗。請省略 SQL 陳述式結尾的分號。詳情請參閱「支援的自訂 SQL 規則類型」和「定義資料品質規則」中的範例。

        4. 按一下 [新增]。

    2. 選用:您可以為任何資料品質規則指派自訂規則名稱,用於監控和警報,以及說明。如要這麼做,請編輯規則並指定下列詳細資料:

      • 規則名稱:輸入自訂規則名稱,最多 63 個半形字元。 規則名稱可包含英文字母 (a-z、A-Z)、數字 (0-9) 和連字號 (-),且開頭須為英文字母,結尾須為數字或英文字母。
      • 說明:輸入規則說明,長度上限為 1,024 個字元。
    3. 重複上述步驟,在資料品質掃描作業中新增其他規則。完成後,按一下「繼續」

  5. 選用步驟:將掃描結果匯出至 BigQuery 標準資料表。在「將掃描結果匯出至 BigQuery 資料表」部分,請執行下列操作:

    1. 在「選取 BigQuery 資料集」欄位中,按一下「瀏覽」。選取用來儲存資料品質掃描結果的 BigQuery 資料集。

    2. 在「BigQuery table」(BigQuery 資料表) 欄位中,指定要儲存資料品質掃描結果的資料表。如果使用現有資料表,請確認該資料表與匯出資料表結構定義相容。如果指定的資料表不存在,Dataplex Universal Catalog 會為您建立。

  6. 選用:新增標籤。標籤是鍵/值組合,可用來將相關物件分組,或與其他 Google Cloud 資源組合。

  7. 選用:設定電子郵件通知報表,在資料品質掃描工作完成時通知使用者。在「通知報表」部分,按一下「新增電子郵件 ID」,然後輸入最多五個電子郵件地址。然後選取要傳送報表的狀況:

    • 品質分數 (<=):如果作業成功,但資料品質分數低於指定目標分數,系統就會傳送報表。輸入介於 0 到 100 之間的分數。
    • 工作失敗:無論資料品質結果如何,只要工作本身失敗,就會傳送報表。
    • 工作完成 (成功或失敗):工作結束時傳送報表,無論資料品質結果為何。
  8. 點選「建立」

    掃描作業建立完成後,只要按一下「立即執行」,即可隨時執行掃描。

gcloud

如要建立資料品質掃描作業,請使用 gcloud dataplex datascans create data-quality 指令

如果來源資料是依 Dataplex Universal Catalog 湖泊整理,請加入 --data-source-entity 旗標:

gcloud dataplex datascans create data-quality DATASCAN \
    --location=LOCATION \
    --data-quality-spec-file=DATA_QUALITY_SPEC_FILE \
    --data-source-entity=DATA_SOURCE_ENTITY

如果來源資料未整理到 Dataplex Universal Catalog 湖泊中,請加入 --data-source-resource 旗標:

gcloud dataplex datascans create data-quality DATASCAN \
    --location=LOCATION \
    --data-quality-spec-file=DATA_QUALITY_SPEC_FILE \
    --data-source-resource=DATA_SOURCE_RESOURCE

請替換下列變數:

  • DATASCAN:資料品質掃描的名稱。
  • LOCATION:要建立資料品質掃描的 Google Cloud 區域。
  • DATA_QUALITY_SPEC_FILE:包含資料品質掃描規格的 JSON 或 YAML 檔案路徑。檔案可以是本機檔案,也可以是前置字串為 gs:// 的 Cloud Storage 路徑。使用這個檔案指定掃描的資料品質規則。您也可以在這個檔案中指定其他詳細資料,例如篩選器、取樣百分比,以及掃描後動作,像是匯出至 BigQuery 或傳送電子郵件通知報告。請參閱 JSON 表示法的說明文件YAML 表示法範例
  • DATA_SOURCE_ENTITY:包含資料的 Dataplex Universal Catalog 實體,用於資料品質掃描。例如 projects/test-project/locations/test-location/lakes/test-lake/zones/test-zone/entities/test-entity
  • DATA_SOURCE_RESOURCE:包含資料品質掃描資料的資源名稱。例如 //bigquery.googleapis.com/projects/test-project/datasets/test-dataset/tables/test-table

C#

C#

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 C# 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog C# API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

using Google.Api.Gax.ResourceNames;
using Google.Cloud.Dataplex.V1;
using Google.LongRunning;

public sealed partial class GeneratedDataScanServiceClientSnippets
{
    /// <summary>Snippet for CreateDataScan</summary>
    /// <remarks>
    /// This snippet has been automatically generated and should be regarded as a code template only.
    /// It will require modifications to work:
    /// - It may require correct/in-range values for request initialization.
    /// - It may require specifying regional endpoints when creating the service client as shown in
    ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public void CreateDataScanRequestObject()
    {
        // Create client
        DataScanServiceClient dataScanServiceClient = DataScanServiceClient.Create();
        // Initialize request argument(s)
        CreateDataScanRequest request = new CreateDataScanRequest
        {
            ParentAsLocationName = LocationName.FromProjectLocation("[PROJECT]", "[LOCATION]"),
            DataScan = new DataScan(),
            DataScanId = "",
            ValidateOnly = false,
        };
        // Make the request
        Operation<DataScan, OperationMetadata> response = dataScanServiceClient.CreateDataScan(request);

        // Poll until the returned long-running operation is complete
        Operation<DataScan, OperationMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        DataScan result = completedResponse.Result;

        // Or get the name of the operation
        string operationName = response.Name;
        // This name can be stored, then the long-running operation retrieved later by name
        Operation<DataScan, OperationMetadata> retrievedResponse = dataScanServiceClient.PollOnceCreateDataScan(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            DataScan retrievedResult = retrievedResponse.Result;
        }
    }
}

Go

Go

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 Go 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog Go API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。


package main

import (
	"context"

	dataplex "cloud.google.com/go/dataplex/apiv1"
	dataplexpb "cloud.google.com/go/dataplex/apiv1/dataplexpb"
)

func main() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := dataplex.NewDataScanClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &dataplexpb.CreateDataScanRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/dataplex/apiv1/dataplexpb#CreateDataScanRequest.
	}
	op, err := c.CreateDataScan(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}

	resp, err := op.Wait(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}

Java

Java

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 Java 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog Java API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

import com.google.cloud.dataplex.v1.CreateDataScanRequest;
import com.google.cloud.dataplex.v1.DataScan;
import com.google.cloud.dataplex.v1.DataScanServiceClient;
import com.google.cloud.dataplex.v1.LocationName;

public class SyncCreateDataScan {

  public static void main(String[] args) throws Exception {
    syncCreateDataScan();
  }

  public static void syncCreateDataScan() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (DataScanServiceClient dataScanServiceClient = DataScanServiceClient.create()) {
      CreateDataScanRequest request =
          CreateDataScanRequest.newBuilder()
              .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
              .setDataScan(DataScan.newBuilder().build())
              .setDataScanId("dataScanId1260787906")
              .setValidateOnly(true)
              .build();
      DataScan response = dataScanServiceClient.createDataScanAsync(request).get();
    }
  }
}

Node.js

Node.js

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 Node.js 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog Node.js API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ** This file is automatically generated by gapic-generator-typescript. **
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **



'use strict';

function main(parent, dataScan, dataScanId) {
  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The resource name of the parent location:
   *  `projects/{project}/locations/{location_id}`
   *  where `project` refers to a *project_id* or *project_number* and
   *  `location_id` refers to a Google Cloud region.
   */
  // const parent = 'abc123'
  /**
   *  Required. DataScan resource.
   */
  // const dataScan = {}
  /**
   *  Required. DataScan identifier.
   *  * Must contain only lowercase letters, numbers and hyphens.
   *  * Must start with a letter.
   *  * Must end with a number or a letter.
   *  * Must be between 1-63 characters.
   *  * Must be unique within the customer project / location.
   */
  // const dataScanId = 'abc123'
  /**
   *  Optional. Only validate the request, but do not perform mutations.
   *  The default is `false`.
   */
  // const validateOnly = true

  // Imports the Dataplex library
  const {DataScanServiceClient} = require('@google-cloud/dataplex').v1;

  // Instantiates a client
  const dataplexClient = new DataScanServiceClient();

  async function callCreateDataScan() {
    // Construct request
    const request = {
      parent,
      dataScan,
      dataScanId,
    };

    // Run request
    const [operation] = await dataplexClient.createDataScan(request);
    const [response] = await operation.promise();
    console.log(response);
  }

  callCreateDataScan();
}

process.on('unhandledRejection', err => {
  console.error(err.message);
  process.exitCode = 1;
});
main(...process.argv.slice(2));

Python

Python

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 Python 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog Python API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
#   client as shown in:
#   https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import dataplex_v1


def sample_create_data_scan():
    # Create a client
    client = dataplex_v1.DataScanServiceClient()

    # Initialize request argument(s)
    data_scan = dataplex_v1.DataScan()
    data_scan.data_quality_spec.rules.dimension = "dimension_value"
    data_scan.data.entity = "entity_value"

    request = dataplex_v1.CreateDataScanRequest(
        parent="parent_value",
        data_scan=data_scan,
        data_scan_id="data_scan_id_value",
    )

    # Make the request
    operation = client.create_data_scan(request=request)

    print("Waiting for operation to complete...")

    response = operation.result()

    # Handle the response
    print(response)

Ruby

Ruby

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 Ruby 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog Ruby API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

require "google/cloud/dataplex/v1"

##
# Snippet for the create_data_scan call in the DataScanService service
#
# This snippet has been automatically generated and should be regarded as a code
# template only. It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in https://cloud.google.com/ruby/docs/reference.
#
# This is an auto-generated example demonstrating basic usage of
# Google::Cloud::Dataplex::V1::DataScanService::Client#create_data_scan.
#
def create_data_scan
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::Dataplex::V1::DataScanService::Client.new

  # Create a request. To set request fields, pass in keyword arguments.
  request = Google::Cloud::Dataplex::V1::CreateDataScanRequest.new

  # Call the create_data_scan method.
  result = client.create_data_scan request

  # The returned object is of type Gapic::Operation. You can use it to
  # check the status of an operation, cancel it, or wait for results.
  # Here is how to wait for a response.
  result.wait_until_done! timeout: 60
  if result.response?
    p result.response
  else
    puts "No response received."
  end
end

REST

如要建立資料品質掃描作業,請使用 dataScans.create 方法

下列要求會建立單次資料品質掃描作業:

POST https://dataplex.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/dataScans?data_scan_id=DATASCAN_ID

{
"data": {
  "resource": "//bigquery.googleapis.com/projects/PROJECT_ID/datasets/DATASET_ID/tables/TABLE_ID"
},
"type": "DATA_QUALITY",
"executionSpec": {
  "trigger": {
    "oneTime": {
      "ttl_after_scan_completion": "120s"
    }
  }
},
"dataQualitySpec": {
  "rules": [
    {
      "nonNullExpectation": {},
      "column": "COLUMN_NAME",
      "dimension": "DIMENSION",
      "threshold": 1
    }
  ]
}
}

更改下列內容:

  • PROJECT_ID:專案 ID。
  • LOCATION:要建立資料品質掃描作業的區域。
  • DATASCAN_ID:資料品質掃描的 ID。
  • DATASET_ID:BigQuery 資料集的 ID。
  • TABLE_ID:BigQuery 資料表的 ID。
  • COLUMN_NAME:規則的資料欄名稱。
  • DIMENSION:規則的維度,例如 VALIDITY

如要根據資料剖析掃描結果,使用規則建議建立資料品質掃描規則,請對資料剖析掃描呼叫 dataScans.jobs.generateDataQualityRules 方法,取得建議。

匯出資料表結構定義

如要將資料品質掃描結果匯出至現有 BigQuery 資料表,請確認該資料表與下列結構定義相容:

資料欄名稱 資料欄的資料類型 子欄位名稱
(如適用)
子欄位資料類型 模式 範例
data_quality_scan struct/record resource_name string 可為空值 //dataplex.googleapis.com/projects/test-project/locations/europe-west2/datascans/test-datascan
project_id string 可為空值 dataplex-back-end-dev-project
location string 可為空值 us-central1
data_scan_id string 可為空值 test-datascan
data_source struct/record resource_name string 可為空值 實體案例:
//dataplex.googleapis.com/projects/dataplex-back-end-dev-project/locations/europe-west2/lakes/a0-datascan-test-lake/zones/a0-datascan-test-zone/entities/table1

表格案例: //bigquery.googleapis.com/projects/test-project/datasets/test-dataset/tables/test-table
dataplex_entity_project_id string 可為空值 dataplex-back-end-dev-project
dataplex_entity_project_number integer 可為空值 123456789
dataplex_lake_id string 可為空值 (僅在來源為實體時有效)
test-lake
dataplex_zone_id string 可為空值 (僅在來源為實體時有效)
test-zone
dataplex_entity_id string 可為空值 (僅在來源為實體時有效)
test-entity
table_project_id string 可為空值 test-project
table_project_number integer 可為空值 987654321
dataset_id string 可為空值 (僅在來源為資料表時有效)
test-dataset
table_id string 可為空值 (僅在來源為資料表時有效)
test-table
data_quality_job_id string 可為空值 caeba234-cfde-4fca-9e5b-fe02a9812e38
data_quality_job_configuration json trigger string 可為空值 ondemand/schedule
incremental boolean 可為空值 true/false
sampling_percent float 可為空值 (0-100)
20.0 (表示 20%)
row_filter string 可為空值 col1 >= 0 AND col2 < 10
job_labels json 可為空值 {"key1":value1}
job_start_time timestamp 可為空值 2023-01-01 00:00:00 UTC
job_end_time timestamp 可為空值 2023-01-01 00:00:00 UTC
job_rows_scanned integer 可為空值 7500
rule_name string 可為空值 test-rule
rule_type string 可為空值 Range Check
rule_evaluation_type string 可為空值 Per row
rule_column string 可為空值 Rule only attached to a certain column
rule_dimension string 可為空值 UNIQUENESS
job_quality_result struct/record passed boolean 可為空值 true/false
score float 可為空值 90.8
job_dimension_result json 可為空值 {"ACCURACY":{"passed":true,"score":100},"CONSISTENCY":{"passed":false,"score":60}}
rule_threshold_percent float 可為空值 (0.0-100.0)
Rule-threshold-pct in API * 100
rule_parameters json 可為空值 {min: 24, max:5345}
rule_pass boolean 可為空值 True
rule_rows_evaluated integer 可為空值 7400
rule_rows_passed integer 可為空值 3
rule_rows_null integer 可為空值 4
rule_failed_records_query string 可為空值 "SELECT * FROM `test-project.test-dataset.test-table` WHERE (NOT((`cTime` >= '15:31:38.776361' and `cTime` <= '19:23:53.754823') IS TRUE));"
rule_assertion_row_count integer 可為空值 10

為資料品質掃描工作設定 BigQueryExport 時,請遵循下列準則:

  • 針對 resultsTable 欄位,請使用下列格式: //bigquery.googleapis.com/projects/{project-id}/datasets/{dataset-id}/tables/{table-id}
  • 使用 BigQuery 標準資料表。
  • 如果建立或更新掃描時資料表不存在,Dataplex Universal Catalog 會為您建立資料表。
  • 根據預設,資料表會依 job_start_time 資料欄每日分區。
  • 如要以其他設定將資料表分區,或是不想分區,請使用所需結構定義和設定重新建立資料表,然後將預先建立的資料表做為結果資料表。
  • 請確認結果資料表與來源資料表位於同一位置。
  • 如果專案已設定 VPC-SC,結果資料表必須與來源資料表位於同一個 VPC-SC 範圍。
  • 如果在掃描執行階段修改資料表,目前執行的工作會匯出至先前的結果資料表,且資料表變更會從下一個掃描工作生效。
  • 請勿修改資料表結構定義。如需自訂資料欄,請在表格上建立檢視畫面。
  • 如要降低費用,請根據用途設定資料分割區的到期日。詳情請參閱「如何設定分區期限」。

執行資料品質掃描

控制台

  1. 在 Google Cloud 控制台,前往 Dataplex Universal Catalog 的「資料剖析與品質」頁面。

    前往「Data profiling & quality」(資料剖析與品質) 頁面

  2. 按一下要執行的資料品質掃描作業。

  3. 按一下 [立即執行]

gcloud

如要執行資料品質掃描,請使用 gcloud dataplex datascans run 指令

gcloud dataplex datascans run DATASCAN \
--location=LOCATION \

請替換下列變數:

  • LOCATION:建立資料品質掃描作業的 Google Cloud 區域。
  • DATASCAN:資料品質掃描的名稱。

C#

C#

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 C# 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog C# API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

using Google.Cloud.Dataplex.V1;

public sealed partial class GeneratedDataScanServiceClientSnippets
{
    /// <summary>Snippet for RunDataScan</summary>
    /// <remarks>
    /// This snippet has been automatically generated and should be regarded as a code template only.
    /// It will require modifications to work:
    /// - It may require correct/in-range values for request initialization.
    /// - It may require specifying regional endpoints when creating the service client as shown in
    ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public void RunDataScanRequestObject()
    {
        // Create client
        DataScanServiceClient dataScanServiceClient = DataScanServiceClient.Create();
        // Initialize request argument(s)
        RunDataScanRequest request = new RunDataScanRequest
        {
            DataScanName = DataScanName.FromProjectLocationDataScan("[PROJECT]", "[LOCATION]", "[DATASCAN]"),
        };
        // Make the request
        RunDataScanResponse response = dataScanServiceClient.RunDataScan(request);
    }
}

Go

Go

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 Go 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog Go API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。


package main

import (
	"context"

	dataplex "cloud.google.com/go/dataplex/apiv1"
	dataplexpb "cloud.google.com/go/dataplex/apiv1/dataplexpb"
)

func main() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := dataplex.NewDataScanClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &dataplexpb.RunDataScanRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/dataplex/apiv1/dataplexpb#RunDataScanRequest.
	}
	resp, err := c.RunDataScan(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}

Java

Java

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 Java 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog Java API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

import com.google.cloud.dataplex.v1.DataScanName;
import com.google.cloud.dataplex.v1.DataScanServiceClient;
import com.google.cloud.dataplex.v1.RunDataScanRequest;
import com.google.cloud.dataplex.v1.RunDataScanResponse;

public class SyncRunDataScan {

  public static void main(String[] args) throws Exception {
    syncRunDataScan();
  }

  public static void syncRunDataScan() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (DataScanServiceClient dataScanServiceClient = DataScanServiceClient.create()) {
      RunDataScanRequest request =
          RunDataScanRequest.newBuilder()
              .setName(DataScanName.of("[PROJECT]", "[LOCATION]", "[DATASCAN]").toString())
              .build();
      RunDataScanResponse response = dataScanServiceClient.runDataScan(request);
    }
  }
}

Python

Python

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 Python 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog Python API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
#   client as shown in:
#   https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import dataplex_v1


def sample_run_data_scan():
    # Create a client
    client = dataplex_v1.DataScanServiceClient()

    # Initialize request argument(s)
    request = dataplex_v1.RunDataScanRequest(
        name="name_value",
    )

    # Make the request
    response = client.run_data_scan(request=request)

    # Handle the response
    print(response)

Ruby

Ruby

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 Ruby 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog Ruby API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

require "google/cloud/dataplex/v1"

##
# Snippet for the run_data_scan call in the DataScanService service
#
# This snippet has been automatically generated and should be regarded as a code
# template only. It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in https://cloud.google.com/ruby/docs/reference.
#
# This is an auto-generated example demonstrating basic usage of
# Google::Cloud::Dataplex::V1::DataScanService::Client#run_data_scan.
#
def run_data_scan
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::Dataplex::V1::DataScanService::Client.new

  # Create a request. To set request fields, pass in keyword arguments.
  request = Google::Cloud::Dataplex::V1::RunDataScanRequest.new

  # Call the run_data_scan method.
  result = client.run_data_scan request

  # The returned object is of type Google::Cloud::Dataplex::V1::RunDataScanResponse.
  p result
end

REST

如要執行資料品質掃描,請使用 dataScans.run 方法

查看資料品質掃描結果

控制台

  1. 在 Google Cloud 控制台,前往 Dataplex Universal Catalog 的「資料剖析與品質」頁面。

    前往「Data profiling & quality」(資料剖析與品質) 頁面

  2. 按一下資料品質掃描作業的名稱。

    • 「總覽」部分會顯示最近一次工作的相關資訊,包括掃描執行時間、各項工作掃描的記錄數量、所有資料品質檢查是否通過,以及失敗的資料品質檢查數量 (如有)。

    • 「資料品質掃描設定」部分會顯示掃描的詳細資料。

  3. 如要查看工作的詳細資訊,例如指出通過規則百分比的資料品質分數、失敗的規則和工作記錄,請按一下「工作記錄」分頁標籤。然後按一下工作 ID。

gcloud

如要查看資料品質掃描工作的結果,請使用 gcloud dataplex datascans jobs describe 指令

gcloud dataplex datascans jobs describe JOB \
--location=LOCATION \
--datascan=DATASCAN \
--view=FULL

請替換下列變數:

  • JOB:資料品質掃描工作的 ID。
  • LOCATION:建立資料品質掃描作業的 Google Cloud 區域。
  • DATASCAN:工作所屬資料品質掃描的名稱。
  • --view=FULL:如要查看掃描作業結果,請指定 FULL

C#

C#

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 C# 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog C# API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

using Google.Cloud.Dataplex.V1;

public sealed partial class GeneratedDataScanServiceClientSnippets
{
    /// <summary>Snippet for GetDataScan</summary>
    /// <remarks>
    /// This snippet has been automatically generated and should be regarded as a code template only.
    /// It will require modifications to work:
    /// - It may require correct/in-range values for request initialization.
    /// - It may require specifying regional endpoints when creating the service client as shown in
    ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public void GetDataScanRequestObject()
    {
        // Create client
        DataScanServiceClient dataScanServiceClient = DataScanServiceClient.Create();
        // Initialize request argument(s)
        GetDataScanRequest request = new GetDataScanRequest
        {
            DataScanName = DataScanName.FromProjectLocationDataScan("[PROJECT]", "[LOCATION]", "[DATASCAN]"),
            View = GetDataScanRequest.Types.DataScanView.Unspecified,
        };
        // Make the request
        DataScan response = dataScanServiceClient.GetDataScan(request);
    }
}

Go

Go

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 Go 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog Go API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。


package main

import (
	"context"

	dataplex "cloud.google.com/go/dataplex/apiv1"
	dataplexpb "cloud.google.com/go/dataplex/apiv1/dataplexpb"
)

func main() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := dataplex.NewDataScanClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &dataplexpb.GetDataScanRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/dataplex/apiv1/dataplexpb#GetDataScanRequest.
	}
	resp, err := c.GetDataScan(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}

Java

Java

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 Java 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog Java API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

import com.google.cloud.dataplex.v1.DataScan;
import com.google.cloud.dataplex.v1.DataScanName;
import com.google.cloud.dataplex.v1.DataScanServiceClient;
import com.google.cloud.dataplex.v1.GetDataScanRequest;

public class SyncGetDataScan {

  public static void main(String[] args) throws Exception {
    syncGetDataScan();
  }

  public static void syncGetDataScan() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (DataScanServiceClient dataScanServiceClient = DataScanServiceClient.create()) {
      GetDataScanRequest request =
          GetDataScanRequest.newBuilder()
              .setName(DataScanName.of("[PROJECT]", "[LOCATION]", "[DATASCAN]").toString())
              .build();
      DataScan response = dataScanServiceClient.getDataScan(request);
    }
  }
}

Python

Python

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 Python 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog Python API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
#   client as shown in:
#   https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import dataplex_v1


def sample_get_data_scan():
    # Create a client
    client = dataplex_v1.DataScanServiceClient()

    # Initialize request argument(s)
    request = dataplex_v1.GetDataScanRequest(
        name="name_value",
    )

    # Make the request
    response = client.get_data_scan(request=request)

    # Handle the response
    print(response)

Ruby

Ruby

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 Ruby 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog Ruby API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

require "google/cloud/dataplex/v1"

##
# Snippet for the get_data_scan call in the DataScanService service
#
# This snippet has been automatically generated and should be regarded as a code
# template only. It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in https://cloud.google.com/ruby/docs/reference.
#
# This is an auto-generated example demonstrating basic usage of
# Google::Cloud::Dataplex::V1::DataScanService::Client#get_data_scan.
#
def get_data_scan
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::Dataplex::V1::DataScanService::Client.new

  # Create a request. To set request fields, pass in keyword arguments.
  request = Google::Cloud::Dataplex::V1::GetDataScanRequest.new

  # Call the get_data_scan method.
  result = client.get_data_scan request

  # The returned object is of type Google::Cloud::Dataplex::V1::DataScan.
  p result
end

REST

如要查看資料品質掃描結果,請使用 dataScans.get 方法

查看已發布的結果

如果資料品質掃描結果發布為 Dataplex Universal Catalog 中繼資料,您可以在Google Cloud 控制台的 BigQuery 和 Dataplex Universal Catalog 頁面,以及來源資料表的「資料品質」分頁中,查看最新的掃描結果。

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

    前往「Search」(搜尋) 頁面

  2. 搜尋並選取資料表。

  3. 按一下「資料品質」分頁標籤。

    系統會顯示最新發布的結果。

查看歷來掃描結果

Dataplex Universal Catalog 會儲存最近 300 項工作或過去一年的資料品質掃描記錄 (以先到者為準)。

控制台

  1. 在 Google Cloud 控制台,前往 Dataplex Universal Catalog 的「資料剖析與品質」頁面。

    前往「Data profiling & quality」(資料剖析與品質) 頁面

  2. 按一下資料品質掃描作業的名稱。

  3. 按一下「工作記錄」分頁標籤。

    「工作記錄」分頁提供過去工作相關資訊,例如每項工作掃描的記錄數量、工作狀態、工作執行時間,以及每項規則是否通過。

  4. 如要查看工作的詳細資訊,請按一下「工作 ID」欄中的任何工作。

gcloud

如要查看歷來資料品質掃描工作,請使用 gcloud dataplex datascans jobs list 指令

gcloud dataplex datascans jobs list \
--location=LOCATION \
--datascan=DATASCAN \

請替換下列變數:

  • LOCATION:建立資料品質掃描作業的 Google Cloud 區域。
  • DATASCAN:要查看歷史記錄作業的資料品質掃描名稱。

C#

C#

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 C# 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog C# API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

using Google.Api.Gax;
using Google.Cloud.Dataplex.V1;
using System;

public sealed partial class GeneratedDataScanServiceClientSnippets
{
    /// <summary>Snippet for ListDataScanJobs</summary>
    /// <remarks>
    /// This snippet has been automatically generated and should be regarded as a code template only.
    /// It will require modifications to work:
    /// - It may require correct/in-range values for request initialization.
    /// - It may require specifying regional endpoints when creating the service client as shown in
    ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public void ListDataScanJobsRequestObject()
    {
        // Create client
        DataScanServiceClient dataScanServiceClient = DataScanServiceClient.Create();
        // Initialize request argument(s)
        ListDataScanJobsRequest request = new ListDataScanJobsRequest
        {
            ParentAsDataScanName = DataScanName.FromProjectLocationDataScan("[PROJECT]", "[LOCATION]", "[DATASCAN]"),
            Filter = "",
        };
        // Make the request
        PagedEnumerable<ListDataScanJobsResponse, DataScanJob> response = dataScanServiceClient.ListDataScanJobs(request);

        // Iterate over all response items, lazily performing RPCs as required
        foreach (DataScanJob item in response)
        {
            // Do something with each item
            Console.WriteLine(item);
        }

        // Or iterate over pages (of server-defined size), performing one RPC per page
        foreach (ListDataScanJobsResponse page in response.AsRawResponses())
        {
            // Do something with each page of items
            Console.WriteLine("A page of results:");
            foreach (DataScanJob item in page)
            {
                // Do something with each item
                Console.WriteLine(item);
            }
        }

        // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
        int pageSize = 10;
        Page<DataScanJob> singlePage = response.ReadPage(pageSize);
        // Do something with the page of items
        Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
        foreach (DataScanJob item in singlePage)
        {
            // Do something with each item
            Console.WriteLine(item);
        }
        // Store the pageToken, for when the next page is required.
        string nextPageToken = singlePage.NextPageToken;
    }
}

Go

Go

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 Go 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog Go API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。


package main

import (
	"context"

	dataplex "cloud.google.com/go/dataplex/apiv1"
	dataplexpb "cloud.google.com/go/dataplex/apiv1/dataplexpb"
	"google.golang.org/api/iterator"
)

func main() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := dataplex.NewDataScanClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &dataplexpb.ListDataScanJobsRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/dataplex/apiv1/dataplexpb#ListDataScanJobsRequest.
	}
	it := c.ListDataScanJobs(ctx, req)
	for {
		resp, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			// TODO: Handle error.
		}
		// TODO: Use resp.
		_ = resp

		// If you need to access the underlying RPC response,
		// you can do so by casting the `Response` as below.
		// Otherwise, remove this line. Only populated after
		// first call to Next(). Not safe for concurrent access.
		_ = it.Response.(*dataplexpb.ListDataScanJobsResponse)
	}
}

Java

Java

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 Java 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog Java API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

import com.google.cloud.dataplex.v1.DataScanJob;
import com.google.cloud.dataplex.v1.DataScanName;
import com.google.cloud.dataplex.v1.DataScanServiceClient;
import com.google.cloud.dataplex.v1.ListDataScanJobsRequest;

public class SyncListDataScanJobs {

  public static void main(String[] args) throws Exception {
    syncListDataScanJobs();
  }

  public static void syncListDataScanJobs() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (DataScanServiceClient dataScanServiceClient = DataScanServiceClient.create()) {
      ListDataScanJobsRequest request =
          ListDataScanJobsRequest.newBuilder()
              .setParent(DataScanName.of("[PROJECT]", "[LOCATION]", "[DATASCAN]").toString())
              .setPageSize(883849137)
              .setPageToken("pageToken873572522")
              .setFilter("filter-1274492040")
              .build();
      for (DataScanJob element : dataScanServiceClient.listDataScanJobs(request).iterateAll()) {
        // doThingsWith(element);
      }
    }
  }
}

Python

Python

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 Python 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog Python API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
#   client as shown in:
#   https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import dataplex_v1


def sample_list_data_scan_jobs():
    # Create a client
    client = dataplex_v1.DataScanServiceClient()

    # Initialize request argument(s)
    request = dataplex_v1.ListDataScanJobsRequest(
        parent="parent_value",
    )

    # Make the request
    page_result = client.list_data_scan_jobs(request=request)

    # Handle the response
    for response in page_result:
        print(response)

Ruby

Ruby

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 Ruby 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog Ruby API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

require "google/cloud/dataplex/v1"

##
# Snippet for the list_data_scan_jobs call in the DataScanService service
#
# This snippet has been automatically generated and should be regarded as a code
# template only. It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in https://cloud.google.com/ruby/docs/reference.
#
# This is an auto-generated example demonstrating basic usage of
# Google::Cloud::Dataplex::V1::DataScanService::Client#list_data_scan_jobs.
#
def list_data_scan_jobs
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::Dataplex::V1::DataScanService::Client.new

  # Create a request. To set request fields, pass in keyword arguments.
  request = Google::Cloud::Dataplex::V1::ListDataScanJobsRequest.new

  # Call the list_data_scan_jobs method.
  result = client.list_data_scan_jobs request

  # The returned object is of type Gapic::PagedEnumerable. You can iterate
  # over elements, and API calls will be issued to fetch pages as needed.
  result.each do |item|
    # Each element is of type ::Google::Cloud::Dataplex::V1::DataScanJob.
    p item
  end
end

REST

如要查看歷來資料品質掃描工作,請使用 dataScans.jobs.list 方法

授予資料品質掃描結果的存取權

如要讓貴機構使用者查看掃描結果,請按照下列步驟操作:

  1. 在 Google Cloud 控制台,前往 Dataplex Universal Catalog 的「資料剖析與品質」頁面。

    前往「Data profiling & quality」(資料剖析與品質) 頁面

  2. 按一下要分享結果的資料品質掃描。

  3. 按一下「Permissions」(權限) 分頁標籤。

  4. 請完成下列步驟:

    • 如要授予主體存取權,請按一下「授予存取權」。將「Dataplex DataScan 資料檢視者」角色授予相關聯的主體。
    • 如要移除主體的存取權,請選取要移除 Dataplex DataScan DataViewer 角色的主體。依序點選 「移除存取權」,然後在系統提示時確認。

在 Cloud Logging 中設定快訊

如要使用 Cloud Logging 中的記錄檔設定資料品質失敗警報,請按照下列步驟操作:

控制台

  1. 前往 Google Cloud 控制台的 Cloud Logging「Logs Explorer」

    前往「Logs explorer」(記錄檔探索工具)

  2. 在「Query」(查詢) 視窗中輸入查詢。請參閱查詢範例

  3. 按一下 [Run Query] (執行查詢)。

  4. 按一下「建立快訊」。系統隨即會開啟側邊面板。

  5. 輸入快訊政策名稱,然後點選「下一步」

  6. 查看查詢。

    1. 按一下「預覽記錄」按鈕,測試查詢。系統會顯示符合條件的記錄。

    2. 點選 [下一步]。

  7. 設定通知間隔時間,然後按一下「下一步」

  8. 定義快訊通知對象,然後按一下「儲存」建立快訊政策。

或者,您也可以在Google Cloud 控制台中依序前往「Monitoring」>「Alerting」,設定及編輯快訊。

gcloud

不支援。

REST

如要進一步瞭解如何在 Cloud Logging 中設定快訊,請參閱「使用 Monitoring API 建立以記錄為基礎的快訊政策」。

設定工作層級或維度層級快訊的查詢範例

  • 以下是範例查詢,可針對資料品質掃描的整體資料品質失敗設定快訊:

    resource.type="dataplex.googleapis.com/DataScan"
    AND labels."dataplex.googleapis.com/data_scan_state"="SUCCEEDED"
    AND resource.labels.resource_container="projects/112233445566"
    AND resource.labels.datascan_id="a0-test-dec6-dq-3"
    AND NOT jsonPayload.dataQuality.passed=true
    
  • 以下是範例查詢,可針對特定資料品質掃描作業的維度 (例如唯一性) 設定資料品質失敗警報:

    resource.type="dataplex.googleapis.com/DataScan"
    AND labels."dataplex.googleapis.com/data_scan_state"="SUCCEEDED"
    AND resource.labels.resource_container="projects/112233445566"
    AND resource.labels.datascan_id="a0-test-dec6-dq-3"
    AND jsonPayload.dataQuality.dimensionPassed.UNIQUENESS=false
    
  • 設定資料表資料品質失敗警報的範例查詢。

    • 針對未在 Dataplex Universal Catalog lake 中整理的 BigQuery 資料表,設定資料品質失敗的快訊:

      resource.type="dataplex.googleapis.com/DataScan"
      AND jsonPayload.dataSource="//bigquery.googleapis.com/projects/test-project/datasets/testdataset/table/chicago_taxi_trips"
      AND labels."dataplex.googleapis.com/data_scan_state"="SUCCEEDED"
      AND resource.labels.resource_container="projects/112233445566"
      AND NOT jsonPayload.dataQuality.passed=true
      
    • 針對 Dataplex Universal Catalog lake 中整理的 BigQuery 資料表,設定資料品質失敗警報:

      resource.type="dataplex.googleapis.com/DataScan"
      AND jsonPayload.dataSource="projects/test-project/datasets/testdataset/table/chicago_taxi_trips"
      AND labels."dataplex.googleapis.com/data_scan_state"="SUCCEEDED"
      AND resource.labels.resource_container="projects/112233445566"
      AND NOT jsonPayload.dataQuality.passed=true
      

設定每項規則快訊的查詢範例

  • 以下是範例查詢,可針對資料品質掃描作業中所有失敗的資料品質規則,以及指定自訂規則名稱設定快訊:

    resource.type="dataplex.googleapis.com/DataScan"
    AND jsonPayload.ruleName="custom-name"
    AND jsonPayload.result="FAILED"
    
  • 以下是範例查詢,可針對資料品質掃描作業,為特定評估類型中所有失敗的資料品質規則設定快訊:

    resource.type="dataplex.googleapis.com/DataScan"
    AND jsonPayload.evalutionType="PER_ROW"
    AND jsonPayload.result="FAILED"
    
  • 以下是範例查詢,可針對資料品質掃描所用資料表中資料欄的所有失敗資料品質規則設定快訊:

    resource.type="dataplex.googleapis.com/DataScan"
    AND jsonPayload.column="CInteger"
    AND jsonPayload.result="FAILED"
    

排解資料品質失敗問題

針對每個含有失敗的資料列層級規則的工作,Dataplex Universal Catalog 都會提供查詢,以取得失敗的記錄。執行這項查詢,即可查看不符合規則的記錄。

控制台

  1. 在 Google Cloud 控制台,前往 Dataplex Universal Catalog 的「資料剖析與品質」頁面。

    前往「Data profiling & quality」(資料剖析與品質) 頁面

  2. 按一下要排解記錄問題的資料品質掃描名稱。

  3. 按一下「工作記錄」分頁標籤。

  4. 按一下找出資料品質失敗的工作 ID。

  5. 在隨即開啟的工作結果視窗中,找到「規則」部分的「查詢以取得失敗記錄」欄。按一下失敗規則的「將查詢複製到剪貼簿」

  6. 在 BigQuery 中執行查詢,查看導致工作失敗的記錄。

gcloud

不支援。

REST

  1. 如要取得找出資料品質失敗的工作,請使用 dataScans.get 方法

    在回應物件中,failingRowsQuery 欄位會顯示查詢。

  2. 在 BigQuery 中執行查詢,查看導致工作失敗的記錄。

管理特定資料表的資料品質掃描作業

本文將說明如何使用 Google Cloud 控制台的 Dataplex Universal Catalog「資料剖析與品質」頁面,管理專案中的資料剖析掃描作業。

您也可以在處理特定資料表時,建立及管理資料剖析掃描作業。在 Google Cloud 控制台的資料表 Dataplex Universal Catalog 頁面,使用「資料品質」分頁標籤。請完成下列步驟:

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

    前往「Search」(搜尋) 頁面

    搜尋並選取資料表。

  2. 按一下「資料品質」分頁標籤。

  3. 視資料表是否已執行資料品質掃描,並將結果發布為 Dataplex Universal Catalog 中繼資料而定,您可以透過下列方式使用資料表的資料品質掃描:

    • 發布資料品質掃描結果:頁面會顯示最新的掃描結果。

      如要管理這份資料表的資料品質掃描,請按一下「資料品質掃描」,然後選取下列選項:

      • 建立新的掃描作業:建立新的資料品質掃描作業。詳情請參閱本文的「建立資料品質掃描作業」一節。從資料表的詳細資料頁面建立掃描時,系統會預先選取該資料表。

      • 「立即執行」:執行掃描。

      • 編輯掃描設定:編輯顯示名稱、篩選條件和排程等設定。

        如要編輯資料品質規則,請在「資料品質」分頁中,按一下「規則」分頁。按一下「修改規則」。更新規則,然後按一下「儲存」

      • 管理掃描作業權限:控管哪些人可以存取掃描結果。 詳情請參閱本文的「授予資料品質掃描結果的存取權」一節。

      • 查看歷來結果:查看先前資料品質掃描工作的詳細資訊。詳情請參閱本文件的「查看資料品質掃描結果」和「查看歷來掃描結果」部分。

      • 查看所有掃描作業:查看適用於這個資料表的資料品質掃描作業清單。

    • 不發布資料品質掃描結果:從下列選項中選取:

      • 建立資料品質掃描作業:建立新的資料品質掃描作業。詳情請參閱本文的「建立資料品質掃描作業」一節。從資料表的詳細資料頁面建立掃描時,系統會預先選取該資料表。

      • 查看現有掃描作業:查看適用於這個資料表的資料品質掃描作業清單。

更新資料品質掃描作業

您可以編輯現有資料品質掃描作業的各種設定,例如顯示名稱、篩選器、時間表和資料品質規則。

控制台

  1. 在 Google Cloud 控制台,前往 Dataplex Universal Catalog 的「資料剖析與品質」頁面。

    前往「Data profiling & quality」(資料剖析與品質) 頁面

  2. 按一下資料品質掃描作業的名稱。

  3. 如要編輯顯示名稱、篩選器和時間表等設定,請按一下「編輯」。編輯值,然後按一下「儲存」

  4. 如要編輯資料品質規則,請在掃描詳細資料頁面中,按一下「目前的規則」分頁標籤。按一下「修改規則」。更新規則,然後按一下「儲存」

gcloud

如要更新資料品質掃描的說明,請使用 gcloud dataplex datascans update data-quality 指令

gcloud dataplex datascans update data-quality DATASCAN \
--location=LOCATION \
--description=DESCRIPTION

更改下列內容:

  • DATASCAN:要更新的資料品質掃描名稱。
  • LOCATION:建立資料品質掃描作業的 Google Cloud 區域。
  • DESCRIPTION:資料品質掃描的新說明。

C#

C#

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 C# 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog C# API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

using Google.Cloud.Dataplex.V1;
using Google.LongRunning;
using Google.Protobuf.WellKnownTypes;

public sealed partial class GeneratedDataScanServiceClientSnippets
{
    /// <summary>Snippet for UpdateDataScan</summary>
    /// <remarks>
    /// This snippet has been automatically generated and should be regarded as a code template only.
    /// It will require modifications to work:
    /// - It may require correct/in-range values for request initialization.
    /// - It may require specifying regional endpoints when creating the service client as shown in
    ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public void UpdateDataScanRequestObject()
    {
        // Create client
        DataScanServiceClient dataScanServiceClient = DataScanServiceClient.Create();
        // Initialize request argument(s)
        UpdateDataScanRequest request = new UpdateDataScanRequest
        {
            DataScan = new DataScan(),
            UpdateMask = new FieldMask(),
            ValidateOnly = false,
        };
        // Make the request
        Operation<DataScan, OperationMetadata> response = dataScanServiceClient.UpdateDataScan(request);

        // Poll until the returned long-running operation is complete
        Operation<DataScan, OperationMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        DataScan result = completedResponse.Result;

        // Or get the name of the operation
        string operationName = response.Name;
        // This name can be stored, then the long-running operation retrieved later by name
        Operation<DataScan, OperationMetadata> retrievedResponse = dataScanServiceClient.PollOnceUpdateDataScan(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            DataScan retrievedResult = retrievedResponse.Result;
        }
    }
}

Go

Go

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 Go 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog Go API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。


package main

import (
	"context"

	dataplex "cloud.google.com/go/dataplex/apiv1"
	dataplexpb "cloud.google.com/go/dataplex/apiv1/dataplexpb"
)

func main() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := dataplex.NewDataScanClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &dataplexpb.UpdateDataScanRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/dataplex/apiv1/dataplexpb#UpdateDataScanRequest.
	}
	op, err := c.UpdateDataScan(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}

	resp, err := op.Wait(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}

Java

Java

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 Java 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog Java API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

import com.google.cloud.dataplex.v1.DataScan;
import com.google.cloud.dataplex.v1.DataScanServiceClient;
import com.google.cloud.dataplex.v1.UpdateDataScanRequest;
import com.google.protobuf.FieldMask;

public class SyncUpdateDataScan {

  public static void main(String[] args) throws Exception {
    syncUpdateDataScan();
  }

  public static void syncUpdateDataScan() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (DataScanServiceClient dataScanServiceClient = DataScanServiceClient.create()) {
      UpdateDataScanRequest request =
          UpdateDataScanRequest.newBuilder()
              .setDataScan(DataScan.newBuilder().build())
              .setUpdateMask(FieldMask.newBuilder().build())
              .setValidateOnly(true)
              .build();
      DataScan response = dataScanServiceClient.updateDataScanAsync(request).get();
    }
  }
}

Python

Python

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 Python 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog Python API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
#   client as shown in:
#   https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import dataplex_v1


def sample_update_data_scan():
    # Create a client
    client = dataplex_v1.DataScanServiceClient()

    # Initialize request argument(s)
    data_scan = dataplex_v1.DataScan()
    data_scan.data_quality_spec.rules.dimension = "dimension_value"
    data_scan.data.entity = "entity_value"

    request = dataplex_v1.UpdateDataScanRequest(
        data_scan=data_scan,
    )

    # Make the request
    operation = client.update_data_scan(request=request)

    print("Waiting for operation to complete...")

    response = operation.result()

    # Handle the response
    print(response)

Ruby

Ruby

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 Ruby 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog Ruby API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

require "google/cloud/dataplex/v1"

##
# Snippet for the update_data_scan call in the DataScanService service
#
# This snippet has been automatically generated and should be regarded as a code
# template only. It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in https://cloud.google.com/ruby/docs/reference.
#
# This is an auto-generated example demonstrating basic usage of
# Google::Cloud::Dataplex::V1::DataScanService::Client#update_data_scan.
#
def update_data_scan
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::Dataplex::V1::DataScanService::Client.new

  # Create a request. To set request fields, pass in keyword arguments.
  request = Google::Cloud::Dataplex::V1::UpdateDataScanRequest.new

  # Call the update_data_scan method.
  result = client.update_data_scan request

  # The returned object is of type Gapic::Operation. You can use it to
  # check the status of an operation, cancel it, or wait for results.
  # Here is how to wait for a response.
  result.wait_until_done! timeout: 60
  if result.response?
    p result.response
  else
    puts "No response received."
  end
end

REST

如要編輯資料品質掃描作業,請使用 dataScans.patch 方法

刪除資料品質掃描作業

控制台

控制台

  1. 在 Google Cloud 控制台,前往 Dataplex Universal Catalog 的「資料剖析與品質」頁面。

    前往「Data profiling & quality」(資料剖析與品質) 頁面

  2. 按一下要刪除的掃描檔。

  3. 按一下「Delete」(刪除),然後在系統提示時確認刪除。

gcloud

gcloud

如要刪除資料品質掃描作業,請使用 gcloud dataplex datascans delete 指令

gcloud dataplex datascans delete DATASCAN \
--location=LOCATION \
--async

請替換下列變數:

  • DATASCAN:要刪除的資料品質掃描名稱。
  • LOCATION:建立資料品質掃描作業的 Google Cloud 區域。

C#

C#

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 C# 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog C# API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

using Google.Cloud.Dataplex.V1;
using Google.LongRunning;
using Google.Protobuf.WellKnownTypes;

public sealed partial class GeneratedDataScanServiceClientSnippets
{
    /// <summary>Snippet for DeleteDataScan</summary>
    /// <remarks>
    /// This snippet has been automatically generated and should be regarded as a code template only.
    /// It will require modifications to work:
    /// - It may require correct/in-range values for request initialization.
    /// - It may require specifying regional endpoints when creating the service client as shown in
    ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public void DeleteDataScanRequestObject()
    {
        // Create client
        DataScanServiceClient dataScanServiceClient = DataScanServiceClient.Create();
        // Initialize request argument(s)
        DeleteDataScanRequest request = new DeleteDataScanRequest
        {
            DataScanName = DataScanName.FromProjectLocationDataScan("[PROJECT]", "[LOCATION]", "[DATASCAN]"),
            Force = false,
        };
        // Make the request
        Operation<Empty, OperationMetadata> response = dataScanServiceClient.DeleteDataScan(request);

        // Poll until the returned long-running operation is complete
        Operation<Empty, OperationMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        Empty result = completedResponse.Result;

        // Or get the name of the operation
        string operationName = response.Name;
        // This name can be stored, then the long-running operation retrieved later by name
        Operation<Empty, OperationMetadata> retrievedResponse = dataScanServiceClient.PollOnceDeleteDataScan(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            Empty retrievedResult = retrievedResponse.Result;
        }
    }
}

Go

Go

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 Go 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog Go API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。


package main

import (
	"context"

	dataplex "cloud.google.com/go/dataplex/apiv1"
	dataplexpb "cloud.google.com/go/dataplex/apiv1/dataplexpb"
)

func main() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := dataplex.NewDataScanClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &dataplexpb.DeleteDataScanRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/dataplex/apiv1/dataplexpb#DeleteDataScanRequest.
	}
	op, err := c.DeleteDataScan(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}

	err = op.Wait(ctx)
	if err != nil {
		// TODO: Handle error.
	}
}

Java

Java

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 Java 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog Java API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

import com.google.cloud.dataplex.v1.DataScanName;
import com.google.cloud.dataplex.v1.DataScanServiceClient;
import com.google.cloud.dataplex.v1.DeleteDataScanRequest;
import com.google.protobuf.Empty;

public class SyncDeleteDataScan {

  public static void main(String[] args) throws Exception {
    syncDeleteDataScan();
  }

  public static void syncDeleteDataScan() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (DataScanServiceClient dataScanServiceClient = DataScanServiceClient.create()) {
      DeleteDataScanRequest request =
          DeleteDataScanRequest.newBuilder()
              .setName(DataScanName.of("[PROJECT]", "[LOCATION]", "[DATASCAN]").toString())
              .setForce(true)
              .build();
      dataScanServiceClient.deleteDataScanAsync(request).get();
    }
  }
}

Python

Python

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 Python 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog Python API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
#   client as shown in:
#   https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import dataplex_v1


def sample_delete_data_scan():
    # Create a client
    client = dataplex_v1.DataScanServiceClient()

    # Initialize request argument(s)
    request = dataplex_v1.DeleteDataScanRequest(
        name="name_value",
    )

    # Make the request
    operation = client.delete_data_scan(request=request)

    print("Waiting for operation to complete...")

    response = operation.result()

    # Handle the response
    print(response)

Ruby

Ruby

在試用這個範例之前,請先按照「使用用戶端程式庫的 Dataplex Universal Catalog 快速入門導覽課程」中的 Ruby 設定操作說明進行操作。詳情請參閱 Dataplex Universal Catalog Ruby API 參考文件

如要向 Dataplex Universal Catalog 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

require "google/cloud/dataplex/v1"

##
# Snippet for the delete_data_scan call in the DataScanService service
#
# This snippet has been automatically generated and should be regarded as a code
# template only. It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in https://cloud.google.com/ruby/docs/reference.
#
# This is an auto-generated example demonstrating basic usage of
# Google::Cloud::Dataplex::V1::DataScanService::Client#delete_data_scan.
#
def delete_data_scan
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::Dataplex::V1::DataScanService::Client.new

  # Create a request. To set request fields, pass in keyword arguments.
  request = Google::Cloud::Dataplex::V1::DeleteDataScanRequest.new

  # Call the delete_data_scan method.
  result = client.delete_data_scan request

  # The returned object is of type Gapic::Operation. You can use it to
  # check the status of an operation, cancel it, or wait for results.
  # Here is how to wait for a response.
  result.wait_until_done! timeout: 60
  if result.response?
    p result.response
  else
    puts "No response received."
  end
end

REST

REST

如要刪除資料品質掃描作業,請使用 dataScans.delete 方法

後續步驟