建立及使用資料剖析掃描

Dataplex Universal Catalog 可協助您找出 BigQuery 資料表中資料欄的常見統計特徵 (常見值、資料分佈、空值計數)。這項資訊有助於您更有效地瞭解及分析資料。

如要進一步瞭解 Dataplex Universal Catalog 資料剖析掃描作業,請參閱「關於資料剖析」。

事前準備

啟用 Dataplex API。

啟用 API 時所需的角色

如要啟用 API,您需要服務使用情形管理員 IAM 角色 (roles/serviceusage.serviceUsageAdmin),其中包含 serviceusage.services.enable 權限。瞭解如何授予角色

啟用 API

必要角色和權限

本節說明使用 Dataplex Universal Catalog 資料剖析掃描作業時,所需的 IAM 角色和權限。

使用者角色和權限

如要取得建立及管理資料剖析掃描作業所需的權限,請要求管理員授予您下列 IAM 角色:

  • 建立、執行、更新及刪除資料剖析檔掃描作業: 在包含資料掃描作業的專案中,具有 Dataplex DataScan 編輯者 (roles/dataplex.dataScanEditor) 角色
  • 查看資料剖析掃描結果、工作和記錄: Dataplex DataScan 檢視者 (roles/dataplex.dataScanViewer) 在包含資料掃描作業的專案中
  • 將資料剖析掃描結果發布至 Dataplex Universal Catalog: Dataplex Catalog 編輯者 (roles/dataplex.catalogEditor) 在 @bigquery 項目群組上
  • 在「資料設定檔」分頁中,查看 BigQuery 中發布的資料設定檔掃描結果: 資料表的「BigQuery 資料檢視者」 (roles/bigquery.dataViewer)

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

這些預先定義的角色具備建立及管理資料剖析掃描作業所需的權限。如要查看確切的必要權限,請展開「Required permissions」(必要權限) 部分:

所需權限

如要建立及管理資料剖析掃描作業,必須具備下列權限:

  • 建立、執行、更新及刪除資料剖析掃描作業:
    • 專案的 dataplex.datascans.create
    • dataplex.datascans.update 資料掃描
    • dataplex.datascans.delete 資料掃描
    • dataplex.datascans.run 資料掃描
    • dataplex.datascans.get 資料掃描
    • 專案的 dataplex.datascans.list
    • dataplex.dataScanJobs.get 資料掃描工作
    • dataplex.dataScanJobs.list 資料掃描
  • 查看資料剖析掃描結果、工作和記錄:
    • dataplex.datascans.getData 資料掃描
    • 專案的 dataplex.datascans.list
    • dataplex.dataScanJobs.get 資料掃描工作
    • dataplex.dataScanJobs.list 資料掃描
  • 將資料剖析掃描結果發布至 Dataplex Universal Catalog:
    • dataplex.entryGroups.useDataProfileAspect 項目群組
    • bigquery.tables.update 在桌上
    • dataplex.entries.update on entry
  • 在 BigQuery 或 Dataplex Universal Catalog 中查看資料表的已發布資料設定檔結果:
    • bigquery.tables.get 在桌上
    • bigquery.tables.getData 在桌上

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

Dataplex Universal Catalog 服務帳戶角色和權限

為確保 Dataplex Universal Catalog 服務帳戶具備執行資料剖析掃描和匯出結果的必要權限,請要求管理員將下列 IAM 角色授予 Dataplex Universal Catalog 服務帳戶:

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

這些預先定義的角色具備執行資料剖析掃描作業及匯出結果所需的權限。如要查看確切的必要權限,請展開「Required permissions」(必要權限) 部分:

所需權限

如要執行資料剖析掃描作業及匯出結果,您必須具備下列權限:

  • 對 BigQuery 資料執行資料剖析掃描:
    • 專案的 bigquery.jobs.create
    • bigquery.tables.get 在桌上
    • bigquery.tables.getData 在桌上
  • 針對使用 Cloud Storage 資料的 BigQuery 外部資料表執行資料剖析掃描:
    • storage.buckets.get 在 bucket 上
    • storage.objects.get 物件
  • 將資料剖析掃描結果匯出至 BigQuery 資料表:
    • bigquery.tables.create 資料集
    • bigquery.tables.updateData 在桌上

管理員或許還可透過自訂角色或其他預先定義的角色,授予 Dataplex Universal Catalog 服務帳戶這些權限。

如果資料表使用 BigQuery 資料列層級安全性,Dataplex Universal Catalog 只能掃描 Dataplex Universal Catalog 服務帳戶可見的資料列。如要允許 Dataplex Universal Catalog 掃描所有資料列,請將其服務帳戶新增至述詞為 TRUE 的資料列篩選器。

如果資料表使用 BigQuery 資料欄層級安全防護機制,Dataplex Universal Catalog 就必須具備存取權,才能掃描受保護的資料欄。如要授予存取權,請在資料表使用的所有政策標記上,將「Data Catalog Fine-Grained Reader」(roles/datacatalog.fineGrainedReader) 角色指派給 Dataplex Universal Catalog 服務帳戶。建立或更新資料掃描的使用者也需要受保護資料欄的權限。

將角色授予 Dataplex Universal Catalog 服務帳戶

如要執行資料剖析掃描,Dataplex Universal Catalog 會使用服務帳戶,該帳戶必須具備執行 BigQuery 工作和讀取 BigQuery 資料表資料的權限。如要授予必要角色,請按照下列步驟操作:

  1. 取得 Dataplex Universal Catalog 服務帳戶的電子郵件地址。如果您尚未在這個專案中建立資料剖析或資料品質掃描作業,請執行下列 gcloud 指令來產生服務身分:

    gcloud beta services identity create --service=dataplex.googleapis.com
    

    指令會傳回服務帳戶電子郵件,格式如下: service-PROJECT_ID@gcp-sa-dataplex.iam.gserviceaccount.com。

    如果服務帳戶已存在,請在 Google Cloud 主控台的「IAM」(身分與存取權管理) 頁面,查看具有「Dataplex」名稱的主體,即可找到服務帳戶的電子郵件地址。

  2. 在專案中授予服務帳戶「BigQuery 工作使用者」(roles/bigquery.jobUser) 角色。服務帳戶可透過這個角色執行掃描的 BigQuery 工作。

    gcloud projects add-iam-policy-binding PROJECT_ID \
        --member="serviceAccount:service-PROJECT_NUMBER@gcp-sa-dataplex.iam.gserviceaccount.com" \
        --role="roles/bigquery.jobUser"
    

    更改下列內容:

    • PROJECT_ID:您的 Google Cloud 專案 ID。
    • service-PROJECT_NUMBER@gcp-sa-dataplex.iam.gserviceaccount.com:Dataplex Universal Catalog 服務帳戶的電子郵件地址。
  3. 針對要剖析的每個資料表,授予服務帳戶「BigQuery 資料檢視者」(roles/bigquery.dataViewer) 角色。這個角色可授予資料表的唯讀存取權。

    gcloud bigquery tables add-iam-policy-binding DATASET_ID.TABLE_ID \
        --member="serviceAccount:service-PROJECT_NUMBER@gcp-sa-dataplex.iam.gserviceaccount.com" \
        --role="roles/bigquery.dataViewer"
    

    更改下列內容:

    • DATASET_ID:包含資料表的資料集 ID。
    • TABLE_ID:要分析的資料表 ID。
    • service-PROJECT_NUMBER@gcp-sa-dataplex.iam.gserviceaccount.com:Dataplex Universal Catalog 服務帳戶的電子郵件地址。

建立資料剖析掃描

控制台

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

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

  2. 按一下「建立資料剖析掃描」

  3. (選用) 輸入「Display name」(顯示名稱)

  4. 輸入 ID。請參閱「資源命名慣例」。

  5. 選用:輸入說明

  6. 在「Table」(資料表) 欄位中,按一下「Browse」(瀏覽)。選擇要掃描的資料表,然後按一下「選取」

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

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

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

    • 如果選擇「增量資料」,請在「時間戳記資料欄」欄位中,從 BigQuery 資料表選取 DATETIMESTAMP 類型的資料欄,這類資料欄的值只會增加,可用於識別新的記錄。如要以 DATETIMESTAMP 類型的資料欄做為分區依據,建議使用分區資料欄做為時間戳記欄位。
  8. 選用:如要篩選資料,請執行下列任一操作:

    • 如要依資料列篩選,請選取「篩選資料列」核取方塊。 輸入有效的 SQL 運算式,該運算式可搭配 GoogleSQL 語法中的 WHERE 子句使用。例如:col1 >= 0

      篩選器可以是多個資料欄的 SQL 條件組合。例如:col1 >= 0 AND col2 < 10

    • 如要依資料欄篩選,請選取「篩選資料欄」核取方塊。

      • 如要在剖析掃描中加入資料欄,請在「Include columns」(包含資料欄) 欄位中按一下「Browse」(瀏覽)。選取要納入的資料欄,然後按一下「選取」

      • 如要從剖析掃描中排除資料欄,請在「排除資料欄」欄位中按一下「瀏覽」。選取要排除的資料欄,然後按一下「選取」

  9. 如要對資料剖析掃描作業套用取樣,請在「取樣大小」清單中選取取樣百分比。請選擇介於 0.0% 至 100.0% 之間的百分比值,最多可有 3 位小數。

    • 如果是較大的資料集,請選擇較低的取樣百分比。舉例來說,如果資料表大小為 1 PB,且您輸入的值介於 0.1% 到 1.0% 之間,資料剖析檔就會取樣 1 到 10 TB 的資料。

    • 樣本資料中必須至少有 100 筆記錄,才能傳回結果。

    • 如果是增量資料掃描,資料剖析掃描會對最新增量套用取樣。

  10. 選用:在來源資料表的Google Cloud 控制台中,將資料剖析掃描結果發布至 BigQuery 和 Dataplex Universal Catalog 頁面。選取「將結果發布至 Dataplex Catalog」核取方塊。

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

    在下列情況下,可能無法使用發布選項:

    • 您沒有資料表的必要權限。
    • 已將另一項資料剖析掃描設為發布結果。
  11. 在「時間表」部分,選擇下列其中一個選項:

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

    • 隨選:隨選執行資料剖析掃描。

    • 單次執行:立即執行資料剖析掃描作業一次,並在自動刪除時間過後移除掃描作業。這項功能為預先發布版

      • 設定掃描後結果自動刪除時間:自動刪除時間是指資料剖析檔掃描執行後,結果的有效時間長度。如果掃描資料設定檔時未指定自動刪除時間,系統會在 24 小時後自動移除掃描結果。自動刪除時間範圍為 0 秒 (立即刪除) 到 365 天。
  12. 按一下「繼續」

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

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

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

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

  15. 如要建立掃描作業,請按一下「建立」

    如果將排程設為隨選,您也可以按一下「執行掃描」立即執行掃描。

gcloud

如要建立資料剖析掃描,請使用 gcloud dataplex datascans create data-profile 指令

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

gcloud dataplex datascans create data-profile DATASCAN \
--location=LOCATION \
--data-source-entity=DATA_SOURCE_ENTITY

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

gcloud dataplex datascans create data-profile DATASCAN \
--location=LOCATION \
--data-source-resource=DATA_SOURCE_RESOURCE

請替換下列變數:

  • DATASCAN:資料剖析掃描的名稱。
  • LOCATION:建立資料剖析掃描的 Google Cloud 區域。
  • 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();
    }
  }
}

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.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 方法

匯出資料表結構定義

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

資料欄名稱 資料欄的資料類型 子欄位名稱 (如適用) 子欄位資料類型 模式 範例
data_profile_scan struct/record resource_name string 可為空值 //dataplex.googleapis.com/projects/test-project/locations/europe-west2/datascans/test-datascan
project_id string 可為空值 test-project
location string 可為空值 us-central1
data_scan_id string 可為空值 test-datascan
data_source struct/record resource_name string 可為空值

實體案例: //dataplex.googleapis.com/projects/test-project/locations/europe-west2/lakes/test-lake/zones/test-zone/entities/test-entity

表格案例: //bigquery.googleapis.com/projects/test-project/datasets/test-dataset/tables/test-table

dataplex_entity_project_id string 可為空值 test-project
dataplex_entity_project_number integer 可為空值 123456789012
dataplex_lake_id string 可為空值

(僅在來源為實體時有效)

test-lake

dataplex_zone_id string 可為空值

(僅在來源為實體時有效)

test-zone

dataplex_entity_id string 可為空值

(僅在來源為實體時有效)

test-entity

table_project_id string 可為空值 dataplex-table
table_project_number int64 可為空值 345678901234
dataset_id string 可為空值

(僅在來源為資料表時有效)

test-dataset

table_id string 可為空值

(僅在來源為資料表時有效)

test-table

data_profile_job_id string 可為空值 caeba234-cfde-4fca-9e5b-fe02a9812e38
data_profile_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
column_filter json 可為空值 {"include_fields":["col1","col2"], "exclude_fields":["col3"]}
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
column_name string 可為空值 column-1
column_type string 可為空值 string
column_mode string 可為空值 repeated
percent_null float 可為空值

(0.0-100.0)

20.0 (表示 20%)

percent_unique float 可為空值

(0.0-100.0)

92.5

min_string_length integer 可為空值

(僅在資料欄類型為字串時有效)

10

max_string_length integer 可為空值

(僅在資料欄類型為字串時有效)

4

average_string_length float 可為空值

(僅在資料欄類型為字串時有效)

7.2

min_value float 可為空值 (僅在資料欄類型為數值 (整數/浮點數) 時有效)
max_value float 可為空值 (僅在資料欄類型為數值 (整數/浮點數) 時有效)
average_value float 可為空值 (僅在資料欄類型為數值 (整數/浮點數) 時有效)
standard_deviation float 可為空值 (僅在資料欄類型為數值 (整數/浮點數) 時有效)
quartile_lower integer 可為空值 (僅在資料欄類型為數值 (整數/浮點數) 時有效)
quartile_median integer 可為空值 (僅在資料欄類型為數值 (整數/浮點數) 時有效)
quartile_upper integer 可為空值 (僅在資料欄類型為數值 (整數/浮點數) 時有效)
top_n struct/record - repeated value string 可為空值 "4009"
count integer 可為空值 20
percent float 可為空值 10 (表示 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 範圍。
  • 如果在掃描執行階段修改資料表,目前執行的工作會匯出至先前的結果資料表,且資料表變更會從下一個掃描工作生效。
  • 請勿修改資料表結構定義。如需自訂資料欄,請在表格上建立檢視畫面。
  • 如要降低費用,請根據用途設定資料分割區的到期日。詳情請參閱「如何設定分區期限」。

建立多項資料剖析掃描作業

您可以使用 Google Cloud 控制台,同時為 BigQuery 資料集中的多個資料表設定資料剖析掃描作業。

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

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

  2. 按一下「建立資料剖析掃描」

  3. 選取「多項資料剖析掃描作業」選項。

  4. 輸入 ID 前置字串。Dataplex Universal Catalog 會使用提供的前置字串和不重複的後置字串,自動產生掃描 ID。

  5. 為所有資料剖析掃描作業輸入說明

  6. 在「Dataset」(資料集) 欄位中,按一下「Browse」(瀏覽)。選取要從中挑選資料表的資料集。按一下「選取」

  7. 如果資料集屬於多區域,請選取要建立資料剖析掃描作業的區域

  8. 設定掃描的通用設定:

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

    2. 如要對資料剖析掃描套用取樣,請在「取樣大小」清單中選取取樣百分比。

      請選擇介於 0.0% 和 100.0% 之間的百分比值,最多可有 3 位小數。

    3. 選用:在來源資料表的Google Cloud 控制台中,將資料剖析掃描結果發布至 BigQuery 和 Dataplex Universal Catalog 頁面。選取「將結果發布至 Dataplex Catalog」核取方塊。

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

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

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

      • 隨選:視需要執行資料剖析掃描。

      • 一次性執行:立即執行一次資料剖析檔掃描,並在自動刪除時間過後移除掃描作業。這項功能為預先發布版

        • 設定掃描後結果自動刪除:自動刪除時間會定義資料剖析檔掃描在執行後保持有效的時間長度。如果掃描資料設定檔時未指定自動刪除時間,系統會在 24 小時後自動移除掃描結果。自動刪除時間可從 0 秒 (立即刪除) 到 365 天不等。
  9. 按一下「繼續」

  10. 在「選擇資料表」欄位中,按一下「瀏覽」。選擇要掃描的一或多個表格,然後按一下「選取」

  11. 按一下「繼續」

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

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

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

      Dataplex Universal Catalog 會為所有資料剖析掃描作業使用相同的結果資料表。

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

  14. 如要建立掃描作業,請按一下「建立」

    如果將排程設為「隨選」,您也可以點選「執行掃描」立即執行掃描。

執行資料剖析掃描

控制台

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

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

  2. 按一下要執行的資料剖析掃描。
  3. 按一下「立即執行」

gcloud

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

gcloud dataplex datascans run DATASCAN \
--location=LOCATION

請替換下列變數:

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

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 方法

查看已發布的結果

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

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

    前往「Search」(搜尋) 頁面

  2. 搜尋並選取資料表。

  3. 按一下「資料剖析檔」分頁標籤。

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

查看最近一次的資料剖析掃描工作

控制台

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

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

  2. 按一下資料剖析掃描的名稱。

  3. 按一下「最近一次的工作結果」分頁標籤。

    如果至少有一項工作成功完成,最近一次的工作結果分頁就會提供最近一次工作的相關資訊。並列出掃描的資料表欄,以及掃描時發現的欄統計資料。

gcloud

如要查看最近一次成功掃描的資料剖析檔,請使用 gcloud dataplex datascans describe 指令

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

請替換下列變數:

  • DATASCAN:要查看最新作業的資料剖析掃描名稱。
  • LOCATION:建立資料剖析掃描的 Google Cloud 區域。
  • --view=FULL:如要查看掃描工作結果,請指定 FULL

REST

如要查看最近的掃描作業,請使用 dataScans.get 方法

查看歷來掃描結果

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」角色的主體。依序點選 「移除存取權」,然後在系統提示時確認。

管理特定資料表的資料剖析掃描

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

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

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

    前往「Search」(搜尋) 頁面

    搜尋並選取資料表。

  2. 按一下「資料剖析檔」分頁標籤。

  3. 視資料表是否已發布資料剖析掃描結果而定,您可以透過下列方式使用資料表的資料剖析掃描:

    • 已發布資料剖析掃描結果:頁面會顯示最新發布的掃描結果。

      如要管理這個資料表的資料剖析掃描作業,請按一下「資料剖析掃描」,然後選取下列其中一個選項:

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

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

      • 編輯掃描設定:編輯設定,包括顯示名稱、篩選器、取樣大小和時間表。

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

      • 查看歷來結果:查看先前資料剖析掃描工作的詳細資訊。詳情請參閱本文的「查看資料剖析掃描結果」和「查看歷來掃描結果」一節。

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

    • 資料剖析掃描結果未發布:按一下「快速資料剖析檔」旁邊的選單,然後選取下列選項:

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

      • 查看先前的剖析檔:查看適用於這個資料表的資料剖析掃描清單。

更新資料剖析掃描

控制台

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

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

  2. 按一下資料剖析掃描的名稱。

  3. 按一下「編輯」,然後編輯值。

  4. 按一下 [儲存]

gcloud

如要更新資料剖析掃描,請使用 gcloud dataplex datascans update data-profile 指令

gcloud dataplex datascans update data-profile 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.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. 按一下「刪除」,然後在系統提示時確認刪除。

gcloud

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

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

請替換下列變數:

  • DATASCAN:要刪除的資料剖析掃描名稱。
  • LOCATION:建立資料剖析掃描的 Google Cloud 區域。

REST

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

後續步驟