管理層面及豐富中繼資料

在 Knowledge Catalog (舊稱 Dataplex Universal Catalog) 中,切面和切面類型可讓您將結構化中繼資料新增至項目、資料欄和項目連結,藉此描述資料資產及其關係。這類背景資訊可提高資料發現度,並協助您分類個人識別資訊 (PII) 等機密資訊,以便套用資料品質或存取權政策。

如要瞭解切面結構定義、系統與自訂切面類型、目標層級和資料落地限制的概念,請參閱「關於切面和切面類型」。如需整個中繼資料中繼模型的架構總覽,請參閱「關於 Knowledge Catalog 中的中繼資料」。如果您是首次使用 Knowledge Catalog 中繼資料,請參閱「為 BigQuery 資料表新增中繼資料」或「建立及使用組織詞彙」快速入門導覽課程。

事前準備

建立及管理切面類型和切面前,請先完成本節所述的工作。

必要的角色

如要取得建立及管理切面類型和切面所需的權限,請要求管理員授予您專案的下列 IAM 角色。您不需要同時具備所有角色,只要選擇符合特定工作流程的角色或組合即可:

如要取得建立及管理切面類型和切面所需的權限,請要求管理員授予您專案的下列 IAM 角色:

  • 如要以廣泛的管理員權限管理所有目錄資源,包括切面類型和項目: Dataplex Catalog 管理員 (roles/dataplex.catalogAdmin) 或 Dataplex Catalog 編輯者 (roles/dataplex.catalogEditor)
  • 如要僅建立及管理自訂切面類型,並為切面類型管理員提供最小權限存取權:Dataplex 切面類型擁有者 (roles/dataplex.aspectTypeOwner)
  • 如要在建立或修改項目時使用切面類型,並為資料管理員提供最小權限存取權: Dataplex 切面類型使用者 (roles/dataplex.aspectTypeUser)
  • 如要將可重複使用的系統切面類型 (例如 schema、contacts 和 overview) 附加至項目和項目連結:Dataplex 項目和 EntryLink 擁有者 (roles/dataplex.entryOwner)
  • 如要查看切面類型及其 IAM 政策,但不進行修改:Dataplex Catalog 檢視者 (roles/dataplex.catalogViewer)

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

這些預先定義的角色具備建立及管理切面類型和切面所需的權限。如要查看確切的必要權限,請展開「Required permissions」(必要權限) 部分:

所需權限

必須具備下列權限,才能建立及管理切面類型和切面:

  • 建立、查看、列出、更新及刪除切面類型:
    • dataplex.aspectTypes.create
    • dataplex.aspectTypes.get
    • dataplex.aspectTypes.list
    • dataplex.aspectTypes.update
    • dataplex.aspectTypes.delete
  • 使用切面類型充實項目: dataplex.aspectTypes.use
  • 建立、查看、更新及刪除項目和其切面:
    • dataplex.entries.create
    • dataplex.entries.get
    • dataplex.entries.list
    • dataplex.entries.update
    • dataplex.entries.delete
  • 建立、查看、更新及刪除項目連結和其切面:
    • dataplex.entryLinks.create
    • dataplex.entryLinks.get
    • dataplex.entryLinks.list
    • dataplex.entryLinks.update
    • dataplex.entryLinks.delete

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

詳情請參閱「Knowledge Catalog IAM 角色」。

啟用 API

在 Knowledge Catalog 專案中啟用 Dataplex API。如果您使用的是新 Google Cloud 專案,或已啟用 BigQuery API 的專案,系統會預設啟用 Dataplex API。

啟用 API

建立自訂切面類型

控制台

如要在 Google Cloud 控制台建立自訂切面類型,請按照下列子工作操作:

  1. 設定基本詳細資料:

    1. 前往 Google Cloud 控制台的 Knowledge Catalog「Metadata types」(中繼資料類型) 頁面。

      前往「Metadata types」(中繼資料類型) 頁面

    2. 依序點選「切面類型」>「自訂」分頁標籤,然後點選「建立切面類型」。

    3. 在「詳細資料」部分中,輸入以下內容:

      • 選用:顯示名稱:使用者容易使用的切面類型名稱。
      • Aspect type ID:切面類型的專屬 ID。
      • 選用:說明:說明切面類型及其用途。
      • 位置:選取切面類型的位置。建立後即無法修改位置。如要瞭解全域和區域位置的取捨,請參閱「自訂切面類型」。
  2. 定義結構定義範本:

    範本會定義切面類型中分組的中繼資料欄位格式和結構定義。您可以手動定義欄位,也可以從「範本庫」選取入門範本 (例如「資料機密性」、「資料治理」或「資料擷取」),加快建立結構定義。舉例來說,選取「Data Sensitivity」範本會自動新增布林值欄位 Is Encrypted 和 Has PII,以及列舉欄位 PII Type。

    如要手動定義欄位,請按照下列步驟操作:

    1. 在「範本」部分,按一下「新增欄位」。
    2. 在「New field」(新增欄位) 面板中,指定下列項目:
      • 名稱:欄位的 ID。
      • 選用:顯示名稱:容易使用的標籤。
      • 選用:說明:欄位的簡短說明。
      • 類型:選取欄位資料類型。支援的類型包括文字、整數、布林值、日期和時間、雙精度浮點數、列舉、陣列、對應和記錄。
      • 選用:必填:勾選這個核取方塊,使用者附加這個切面時就必須填寫這個欄位。
    3. 點按「Done」(完成)。如要新增更多欄位,請按一下「新增欄位」,然後重複上述步驟。
  3. 新增資源標籤並儲存:

    資源標籤是任意鍵/值組合,可協助您整理及篩選 Google Cloud 資源。舉例來說,您可以使用 environment: production 或 team: analytics 等標籤,依環境或團隊擁有權整理資源。

    1. 在「Labels」(標籤) 專區中,按一下「Add label」(新增標籤)。
    2. 輸入標籤的「鍵」和「值」。
    3. 按一下「儲存」。

gcloud

如要建立自訂切面類型,請使用 gcloud dataplex aspect-types create 指令。

C#

C#

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

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

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

public sealed partial class GeneratedCatalogServiceClientSnippets
{
    /// <summary>Snippet for CreateAspectType</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 CreateAspectTypeRequestObject()
    {
        // Create client
        CatalogServiceClient catalogServiceClient = CatalogServiceClient.Create();
        // Initialize request argument(s)
        CreateAspectTypeRequest request = new CreateAspectTypeRequest
        {
            ParentAsLocationName = LocationName.FromProjectLocation("[PROJECT]", "[LOCATION]"),
            AspectTypeId = "",
            AspectType = new AspectType(),
            ValidateOnly = false,
        };
        // Make the request
        Operation<AspectType, OperationMetadata> response = catalogServiceClient.CreateAspectType(request);

        // Poll until the returned long-running operation is complete
        Operation<AspectType, OperationMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        AspectType 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<AspectType, OperationMetadata> retrievedResponse = catalogServiceClient.PollOnceCreateAspectType(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            AspectType retrievedResult = retrievedResponse.Result;
        }
    }
}

Go

Go

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

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


//go:build examples

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.NewCatalogClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &dataplexpb.CreateAspectTypeRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/dataplex/apiv1/dataplexpb#CreateAspectTypeRequest.
	}
	op, err := c.CreateAspectType(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

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

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

import com.google.cloud.dataplex.v1.AspectType;
import com.google.cloud.dataplex.v1.CatalogServiceClient;
import com.google.cloud.dataplex.v1.CreateAspectTypeRequest;
import com.google.cloud.dataplex.v1.LocationName;

public class SyncCreateAspectType {

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

  public static void syncCreateAspectType() 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 (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
      CreateAspectTypeRequest request =
          CreateAspectTypeRequest.newBuilder()
              .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
              .setAspectTypeId("aspectTypeId-423030675")
              .setAspectType(AspectType.newBuilder().build())
              .setValidateOnly(true)
              .build();
      AspectType response = catalogServiceClient.createAspectTypeAsync(request).get();
    }
  }
}

Node.js

Node.js

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

如要向 Knowledge 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.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Required. The resource name of the AspectType, of the form:
 *  projects/{project_number}/locations/{location_id}
 *  where `location_id` refers to a Google Cloud region.
 */
// const parent = 'abc123'
/**
 *  Required. AspectType identifier.
 */
// const aspectTypeId = 'abc123'
/**
 *  Required. AspectType Resource.
 */
// const aspectType = {}
/**
 *  Optional. The service validates the request without performing any
 *  mutations. The default is false.
 */
// const validateOnly = true

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

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

async function callCreateAspectType() {
  // Construct request
  const request = {
    parent,
    aspectTypeId,
    aspectType,
  };

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

callCreateAspectType();

Python

Python

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

如要向 Knowledge 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_aspect_type():
    # Create a client
    client = dataplex_v1.CatalogServiceClient()

    # Initialize request argument(s)
    aspect_type = dataplex_v1.AspectType()
    aspect_type.metadata_template.name = "name_value"
    aspect_type.metadata_template.type_ = "type__value"

    request = dataplex_v1.CreateAspectTypeRequest(
        parent="parent_value",
        aspect_type_id="aspect_type_id_value",
        aspect_type=aspect_type,
    )

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

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

    response = operation.result()

    # Handle the response
    print(response)

小茹

Ruby

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

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

require "google/cloud/dataplex/v1"

##
# Snippet for the create_aspect_type call in the CatalogService 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::CatalogService::Client#create_aspect_type.
#
def create_aspect_type
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::Dataplex::V1::CatalogService::Client.new

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

  # Call the create_aspect_type method.
  result = client.create_aspect_type 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

如要建立自訂切面類型,請使用 aspectType.create 方法。

建立自訂切面類型後,即可將切面新增至項目。

使用「記錄 ID」和「記錄參照」欄位的範例

您可以使用「Record ID」(記錄 ID) 和「Record reference」(記錄參照) 欄位進行遞迴參照。以下範例說明如何使用這些欄位:

假設有一個名為 Employee 的切面類型,其中包含下列欄位:

  • Name (類型:Text)
  • 開始日期 (類型:Date & time)
  • Designation (類型:Text)
  • 目前地址 (類型:Record)
  • 永久地址 (類型:Record)

「Current address」(現居地址) 和「Permanent address」(永久地址) 這兩個地址欄位屬於相同的資料類型 Record。為避免重複,您可以在定義這些欄位時設定「Record ID」和「Record reference」值。

定義「Current address」(目前地址) 欄位時,您可以將「Record ID」(記錄 ID) 指定為 address-field。在「Permanent address」(永久地址) 部分,您可以為「Record reference」(記錄參照) 指定相同的值 (address-field)。例如:

  • Name (類型:Text)
  • 開始日期 (類型:Date & time)
  • Designation (類型:Text)
  • 目前地址 (類型:Record,記錄 ID:address-field)
  • 永久地址 (類型:Record,記錄參考資料:address-field)

這樣一來,您就不必複製另一個地址的欄位。

為項目新增切面

建立自訂切面類型後,即可建立該類型的切面。如要為項目新增切面,您必須更新項目,因為切面會儲存在項目中。

請注意下列限制:

  • 您可以將切面新增至項目或項目的資料欄。
  • 您只能編輯自訂項目的必要切面。您無法刪除必要面向。
  • 您可以編輯及刪除自訂項目和系統項目的選用層面。
  • 使用 CREATE OR REPLACE TABLE 陳述式、TRUNCATE TABLE 陳述式或 WRITE_TRUNCATE 工作取代或重新載入 BigQuery 資料表時,Knowledge Catalog 會保留項目中由使用者附加的切面。結構定義中保留的資料欄,也會保留資料欄層級 aspect。不過,如果您使用 DROP TABLE 陳述式和 CREATE TABLE 陳述式捨棄並重新建立資料表,Knowledge Catalog 會建立新項目,但不會保留原始資料表的使用者附加切面。如要在重新載入表格時保留特定部分,請使用 CREATE OR REPLACE TABLE、TRUNCATE TABLE 或 WRITE_TRUNCATE。或者,您也可以建立 BigQuery 檢視表,並將切面附加至檢視表。

控制台

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

    前往「Search」(搜尋) 頁面

  2. 搜尋要新增切面的項目,然後按一下該項目。項目詳細資料頁面隨即開啟。

  3. 在項目詳細資料頁面,按一下「Details」(詳細資料) 分頁標籤。

  4. 在「切面」部分,按一下「必要切面」或「選用切面」區域中的「 新增」。只有在項目類型定義了必要切面時,才能新增必要切面。

  5. 搜尋並選取要新增的面向。

  6. 在「Add aspect」(新增切面) 視窗中,輸入各欄位的值。

  7. 按一下「儲存」。

如要為項目資料欄新增切面,請按照下列步驟操作:

  1. 在項目詳細資料頁面中,按一下「Schema」(結構定義) 分頁標籤。
  2. 選取要新增切面的資料欄。
  3. 點選「新增切面」。
  4. 搜尋並選取要新增的面向。
  5. 在「Add aspect」(新增切面) 視窗中,輸入各欄位的值。
  6. 按一下「儲存」。

gcloud

如要將切面新增至項目或項目資料欄,請使用 gcloud dataplex entries update 指令。

C#

C#

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

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

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

public sealed partial class GeneratedCatalogServiceClientSnippets
{
    /// <summary>Snippet for UpdateEntry</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 UpdateEntryRequestObject()
    {
        // Create client
        CatalogServiceClient catalogServiceClient = CatalogServiceClient.Create();
        // Initialize request argument(s)
        UpdateEntryRequest request = new UpdateEntryRequest
        {
            Entry = new Entry(),
            UpdateMask = new FieldMask(),
            AllowMissing = false,
            DeleteMissingAspects = false,
            AspectKeys = { "", },
        };
        // Make the request
        Entry response = catalogServiceClient.UpdateEntry(request);
    }
}

如要為項目物件新增切面,請參閱「切面」。

Go

Go

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

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


//go:build examples

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.NewCatalogClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

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

如要為項目物件新增切面,請參閱「項目」。

Java

Java

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

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

import com.google.cloud.dataplex.v1.Aspect;
import com.google.cloud.dataplex.v1.CatalogServiceClient;
import com.google.cloud.dataplex.v1.Entry;
import com.google.cloud.dataplex.v1.EntryName;
import com.google.cloud.dataplex.v1.EntrySource;
import com.google.protobuf.FieldMask;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
import java.util.Map;

public class UpdateEntry {

  public static void main(String[] args) throws Exception {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "MY_PROJECT_ID";
    // Available locations: https://cloud.google.com/dataplex/docs/locations
    String location = "MY_LOCATION";
    String entryGroupId = "MY_ENTRY_GROUP_ID";
    String entryId = "MY_ENTRY_ID";

    Entry createdEntry = updateEntry(projectId, location, entryGroupId, entryId);
    System.out.println("Successfully updated entry: " + createdEntry.getName());
  }

  // Method to update Entry located in projectId, location, entryGroupId and with entryId
  public static Entry updateEntry(
      String projectId, String location, String entryGroupId, String entryId) throws Exception {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests.
    try (CatalogServiceClient client = CatalogServiceClient.create()) {
      Entry entry =
          Entry.newBuilder()
              .setName(EntryName.of(projectId, location, entryGroupId, entryId).toString())
              .setEntrySource(
                  EntrySource.newBuilder()
                      .setDescription("updated description of the entry")
                      .build())
              .putAllAspects(
                  Map.of(
                      "dataplex-types.global.generic",
                      Aspect.newBuilder()
                          .setAspectType(
                              "projects/dataplex-types/locations/global/aspectTypes/generic")
                          .setData(
                              Struct.newBuilder()
                                  // "Generic" Aspect Type have fields called "type" and "system.
                                  // The values below are a sample of possible options.
                                  .putFields(
                                      "type",
                                      Value.newBuilder()
                                          .setStringValue("updated example value")
                                          .build())
                                  .putFields(
                                      "system",
                                      Value.newBuilder()
                                          .setStringValue("updated example system")
                                          .build())
                                  .build())
                          .build()))
              .build();

      // Update mask specifies which fields will be updated.
      // For more information on update masks, see: https://google.aip.dev/161
      FieldMask updateMask =
          FieldMask.newBuilder().addPaths("aspects").addPaths("entry_source.description").build();
      return client.updateEntry(entry, updateMask);
    }
  }
}

Node.js

Node.js

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

如要向 Knowledge 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.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Required. Entry resource.
 */
// const entry = {}
/**
 *  Optional. Mask of fields to update. To update Aspects, the update_mask must
 *  contain the value "aspects".
 *  If the update_mask is empty, the service will update all modifiable fields
 *  present in the request.
 */
// const updateMask = {}
/**
 *  Optional. If set to true and the entry doesn't exist, the service will
 *  create it.
 */
// const allowMissing = true
/**
 *  Optional. If set to true and the aspect_keys specify aspect ranges, the
 *  service deletes any existing aspects from that range that weren't provided
 *  in the request.
 */
// const deleteMissingAspects = true
/**
 *  Optional. The map keys of the Aspects which the service should modify. It
 *  supports the following syntaxes:
 *  * `<aspect_type_reference>` - matches an aspect of the given type and empty
 *  path.
 *  * `<aspect_type_reference>@path` - matches an aspect of the given type and
 *  specified path. For example, to attach an aspect to a field that is
 *  specified by the `schema` aspect, the path should have the format
 *  `Schema.<field_name>`.
 *  * `<aspect_type_reference>@*` - matches aspects of the given type for all
 *  paths.
 *  * `*@path` - matches aspects of all types on the given path.
 *  The service will not remove existing aspects matching the syntax unless
 *  `delete_missing_aspects` is set to true.
 *  If this field is left empty, the service treats it as specifying
 *  exactly those Aspects present in the request.
 */
// const aspectKeys = ['abc','def']

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

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

async function callUpdateEntry() {
  // Construct request
  const request = {
    entry,
  };

  // Run request
  const response = await dataplexClient.updateEntry(request);
  console.log(response);
}

callUpdateEntry();

Python

Python

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

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

from google.cloud import dataplex_v1
from google.protobuf import struct_pb2


def update_entry(
    project_id: str, location: str, entry_group_id: str, entry_id: str
) -> dataplex_v1.Entry:
    """Method to update Entry located in project_id, location, entry_group_id and with entry_id"""

    # Initialize client that will be used to send requests across threads. This
    # client only needs to be created once, and can be reused for multiple requests.
    # After completing all of your requests, call the "__exit__()" method to safely
    # clean up any remaining background resources. Alternatively, use the client as
    # a context manager.
    with dataplex_v1.CatalogServiceClient() as client:
        # The resource name of the Entry
        name = f"projects/{project_id}/locations/{location}/entryGroups/{entry_group_id}/entries/{entry_id}"
        entry = dataplex_v1.Entry(
            name=name,
            entry_source=dataplex_v1.EntrySource(
                description="updated description of the entry"
            ),
            aspects={
                "dataplex-types.global.generic": dataplex_v1.Aspect(
                    aspect_type="projects/dataplex-types/locations/global/aspectTypes/generic",
                    data=struct_pb2.Struct(
                        fields={
                            # "Generic" Aspect Type have fields called "type" and "system.
                            # The values below are a sample of possible options.
                            "type": struct_pb2.Value(
                                string_value="updated example value"
                            ),
                            "system": struct_pb2.Value(
                                string_value="updated example system"
                            ),
                        }
                    ),
                )
            },
        )

        # Update mask specifies which fields will be updated.
        # For more information on update masks, see: https://google.aip.dev/161
        update_mask = {"paths": ["aspects", "entry_source.description"]}
        return client.update_entry(entry=entry, update_mask=update_mask)


if __name__ == "__main__":
    # TODO(developer): Replace these variables before running the sample.
    project_id = "MY_PROJECT_ID"
    # Available locations: https://cloud.google.com/dataplex/docs/locations
    location = "MY_LOCATION"
    entry_group_id = "MY_ENTRY_GROUP_ID"
    entry_id = "MY_ENTRY_ID"

    updated_entry = update_entry(project_id, location, entry_group_id, entry_id)
    print(f"Successfully updated entry: {updated_entry.name}")

小茹

Ruby

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

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

require "google/cloud/dataplex/v1"

##
# Snippet for the update_entry call in the CatalogService 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::CatalogService::Client#update_entry.
#
def update_entry
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::Dataplex::V1::CatalogService::Client.new

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

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

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

如要為項目物件新增切面,請參閱 #required_aspects=。

REST

如要將切面新增至項目或項目資料欄,請使用 entry.patch 方法。

如果切面類型和項目位於不同的 Google Cloud 組織,則不支援在項目中建立及使用切面。

附加可重複使用的系統切面類型

Knowledge Catalog 提供預先定義的系統切面類型,可附加至項目,擷取標準化中繼資料。舉例來說,您可以使用這些切面類型記錄擁有權聯絡人、結構定義定義、使用指標和資料品質結果。

一般工作流程和酬載規則

附加可重複使用的系統切面類型時,請遵循下列規則:

  • 控制台與 CLI/REST:如果是沒有巢狀欄面的切面類型 (例如 generic),您可以使用 Google Cloud 控制台、gcloud CLI 或 REST API。如果切面類型具有複雜或巢狀結構 (例如 data-quality-scorecard、contacts 或 data-profile),則必須使用 gcloud CLI 或 REST API。
  • 酬載結構:
    • gcloud CLI:直接傳遞切面圖,並以全域切面類型 ID {"dataplex-types.global.<ASPECT_TYPE>": {"data": { ... }}} 做為索引鍵。
    • REST API:將面向對應關係圖包裝在 "aspects" 容器物件中:{"aspects": {"dataplex-types.global.<ASPECT_TYPE>": {"data": { ... }}}}。
  • 覆寫行為:更新切面會取代目標項目或資料欄上該特定切面類型的任何現有資料,不會合併欄位。

以下各節提供附加常見可重複使用系統層面的範例和結構定義,首先是資料品質評量表。

資料品質評量表

資料品質評量表是提供資料品質摘要的面向,通常依據資料品質掃描或其他程序。您可以將資料品質評量表附加至項目,提供自訂資料品質資訊。方法是附加系統定義類型 data-quality-scorecard 的切面。

data-quality-scorecard 剖析中的 data 欄位可包含下列欄位:

  • job:選用。這項記錄包含生成評量表的作業詳細資料。

    • name:資料品質工作的資源名稱。

    • runTime:資料品質工作的執行時間。

  • score:選用。整體資料品質分數。分數範圍介於 [0, 100]。

  • status:必填,資料品質評量表的狀態,指出是否通過品質門檻 (PASS 或 FAIL)。

  • dimensions:選用。維度結果陣列。每項結果都包含:

    • name:維度名稱。可能的值為 ACCURACY、COMPLETENESS、CONSISTENCY、FRESHNESS、UNIQUENESS、VALIDITY 或 VOLUME,或自訂維度名稱。自訂維度名稱必須使用大寫字母,且長度不得超過 30 個字元。

    • score:整體維度層級分數,範圍為 [0, 100]。

    • status:維度的狀態,指出是否通過品質門檻 (PASS 或 FAIL)。

  • columns:選用。資料欄結果陣列。每項結果都包含:

    • name:資料欄名稱。

    • score:資料欄層級的整體分數,範圍介於 [0, 100]。

    • status:資料欄的狀態,指出是否通過品質門檻 (PASS 或 FAIL)。

    • dimensions:資料欄的維度分數陣列。每個維度分數都包含:

      • name:維度名稱。

      • score:維度分數,範圍介於 [0, 100]。

      • status:資料欄維度的狀態,指出是否通過品質門檻 (PASS、FAIL、UNKNOWN 或 NOT_APPLICABLE)。

    • details (選用對應):提供評估相關額外背景資訊的鍵/值組合。

    • evaluatedAssetCount (選用整數):評估的素材資源數量。

執行指令來附加切面時,系統會取代該特定切面的所有現有資料。舉例來說,如果更新分數為 80 的評量表,並上傳分數為 90 的新檔案,系統會覆寫 80。不會合併資料。

如要附加資料品質評量表,請按照下列步驟操作:

gcloud

如要更新項目的切面,請使用 gcloud dataplex entries update-aspects 指令。

  1. 建立 JSON 檔案 (dq-aspect.json),並加入下列內容。

    {
      "dataplex-types.global.data-quality-scorecard": {
        "data": {
          "score": 80,
          "status": "PASS",
          "dimensions": [
            {
              "name": "completeness",
              "score": 90,
              "status": "PASS"
            },
            {
              "name": "uniqueness",
              "score": 70,
              "status": "FAIL"
            }
          ],
          "columns": [
            {
              "name": "col1",
              "score": 85,
              "status": "PASS"
            }
          ]
        }
      }
    }
    
  2. 執行下列指令:

      gcloud dataplex entries update-aspects ENTRY_ID \
      --location=LOCATION \
      --entry-group=ENTRY_GROUP_ID \
      --project=PROJECT_ID \
      --aspects=dq-aspect.json
    

    請替換下列變數:

    • ENTRY_ID:項目的 ID,例如 example-entry
    • LOCATION:項目的位置,例如 us-central1
    • ENTRY_GROUP_ID:項目群組的 ID,例如 example-entry-group
    • PROJECT_ID:專案 ID,例如 example-project

REST

如要更新項目的切面,請使用 entry.patch 方法。

  1. 建立名為 payload.json 的檔案,並將要求中的 JSON 內容貼到該檔案中。

    
      {
        "aspects": {
          "dataplex-types.global.data-quality-scorecard": {
            "data": {
              "score": 80,
              "status": "PASS",
              "dimensions": [
                {
                  "name": "completeness",
                  "score": 90,
                  "status": "PASS"
                },
                {
                  "name": "uniqueness",
                  "score": 70,
                  "status": "FAIL"
                }
              ],
              "columns": [
                {
                  "name": "col1",
                  "score": 85,
                  "status": "PASS"
                }
              ]
            }
          }
        }
      }
    
  2. 在終端機中執行下列指令:

     curl -X PATCH \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json" \
     -d @payload.json \
     "https://dataplex.googleapis.com/v1/projects/<var>PROJECT_ID</var>/locations/<var>LOCATION</var>/entryGroups/<var>ENTRY_GROUP_ID</var>/entries/<var>ENTRY_ID</var>?updateMask=aspects"
    

    更改下列內容:

    • PROJECT_ID:專案 ID,例如 example-project
    • LOCATION:項目的位置,例如 us-central1
    • ENTRY_GROUP_ID:項目群組的 ID,例如 example-entry-group
    • ENTRY_ID:項目 ID,例如 example-entry

其他可重複使用的切面類型

您也可以使用下列系統切面類型來充實項目。以下各節列出前置摘要。點選各個可展開的部分,即可查看欄位結構定義和 JSON 酬載範例。

聯絡人 (dataplex-types.global.contacts)

使用 contacts 類型,將擁有權、管理權或作業角色指派給項目。

  • identities (陣列):聯絡人清單。每個聯絡人包含 role (例如 owner、steward、producer 或 admin)、name 和 id (電子郵件地址)。

酬載範例 (REST API):

{
  "aspects": {
    "dataplex-types.global.contacts": {
      "data": {
        "identities": [
          {
            "role": "steward",
            "name": "Jane Doe",
            "id": "jane.doe@example.com"
          }
        ]
      }
    }
  }
}
    

資料剖析檔 (dataplex-types.global.data-profile)

使用 data-profile 類型,擷取來源資料掃描作業產生的統計剖析結果。詳情請參閱「關於資料剖析」。

  • sourceDataInfo (記錄):掃描作業的中繼資料,包括 scope (PREVIEW、SAMPLED 或 ALL)、scannedRows 和 samplingPercentage。
  • fields (對應):資料欄層級統計資料,包括 nullness、uniqueness,以及數值、字串、日期時間和陣列資料欄的類型專屬指標。

酬載範例 (REST API):

{
  "aspects": {
    "dataplex-types.global.data-profile": {
      "data": {
        "sourceDataInfo": {
          "scope": "ALL",
          "scannedRows": 100
        },
        "fields": {
          "col1": {
            "nullness": 0.0,
            "uniqueness": 0.1,
            "string": {
              "length": {
                "min": 1,
                "max": 20,
                "avg": 12.54
              }
            }
          }
        }
      }
    }
  }
}
    

一般 (dataplex-types.global.generic)

使用 generic 切面類型,即可擷取自由格式的項目資訊和來源系統中繼資料,不必定義自訂切面結構定義。

  • type (字串):使用者指定的項目分類字串。
  • system (字串):自訂項目的來源系統 ID。

酬載範例 (REST API):

{
  "aspects": {
    "dataplex-types.global.generic": {
      "data": {
        "type": "custom-type",
        "system": "custom-system"
      }
    }
  }
}
    

總覽 (dataplex-types.global.overview)

使用 overview 類型,提供人類可讀的 RTF 格式文件和實用的外部連結。

  • content (字串):支援 HTML 格式的 RTF 格式說明。
  • links (陣列):外部資源和說明文件連結,每個連結都包含 url 和 title。

酬載範例 (REST API):

{
  "aspects": {
    "dataplex-types.global.overview": {
      "data": {
        "content": "This is a rich text description.",
        "links": [
          {
            "url": "https://example.com",
            "title": "Example Link"
          }
        ]
      }
    }
  }
}
    

結構定義 (dataplex-types.global.schema)

使用 schema 切面類型,說明資料資產的表格結構定義、資料欄名稱、模式和資料類型。

  • fields (陣列):資料欄清單,每個資料欄包含 name、dataType、metadataType (例如 STRING、BOOLEAN)、mode (NULLABLE、REQUIRED、REPEATED) 和選用的 description。

酬載範例 (REST API):

{
  "aspects": {
    "dataplex-types.global.schema": {
      "data": {
        "fields": [
          {
            "name": "id",
            "dataType": "string",
            "metadataType": "STRING",
            "mode": "REQUIRED"
          }
        ]
      }
    }
  }
}
    

使用量 (dataplex-types.global.usage)

使用 usage 類型追蹤消耗指標、觀看次數和時間序列查詢模式。

  • metrics (陣列):消耗量指標,每個指標都包含 name (例如 views 或 reads) 和 timeSeries 資料點,並附有匯總間隔和值。
  • refreshTime (日期時間):上次計算用量指標的時間戳記。

酬載範例 (REST API):

{
  "aspects": {
    "dataplex-types.global.usage": {
      "data": {
        "metrics": [
          {
            "name": "views",
            "timeSeries": [
              {
                "interval": "30d",
                "value": 100
              }
            ]
          }
        ],
        "refreshTime": "2025-01-01T12:00:00Z"
      }
    }
  }
}
    

建立項目連結

您可以建立項目連結,在兩個項目之間建立關係。

項目連結可以是對稱 (例如 synonym) 或不對稱 (例如 definition)。

C#

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

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

using Google.Cloud.Dataplex.V1;

public sealed partial class GeneratedCatalogServiceClientSnippets
{
    /// <summary>Snippet for CreateEntryLink</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 CreateEntryLinkRequestObject()
    {
        // Create client
        CatalogServiceClient catalogServiceClient = CatalogServiceClient.Create();
        // Initialize request argument(s)
        CreateEntryLinkRequest request = new CreateEntryLinkRequest
        {
            ParentAsEntryGroupName = EntryGroupName.FromProjectLocationEntryGroup("[PROJECT]", "[LOCATION]", "[ENTRY_GROUP]"),
            EntryLinkId = "",
            EntryLink = new EntryLink(),
        };
        // Make the request
        EntryLink response = catalogServiceClient.CreateEntryLink(request);
    }
}

Go

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

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


//go:build examples

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.NewCatalogClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

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

Java

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

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

import com.google.cloud.dataplex.v1.CatalogServiceClient;
import com.google.cloud.dataplex.v1.CreateEntryLinkRequest;
import com.google.cloud.dataplex.v1.EntryGroupName;
import com.google.cloud.dataplex.v1.EntryLink;

public class SyncCreateEntryLink {

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

  public static void syncCreateEntryLink() 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 (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
      CreateEntryLinkRequest request =
          CreateEntryLinkRequest.newBuilder()
              .setParent(EntryGroupName.of("[PROJECT]", "[LOCATION]", "[ENTRY_GROUP]").toString())
              .setEntryLinkId("entryLinkId-1349584441")
              .setEntryLink(EntryLink.newBuilder().build())
              .build();
      EntryLink response = catalogServiceClient.createEntryLink(request);
    }
  }
}

Node.js

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

如要向 Knowledge 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.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Required. The resource name of the parent Entry Group:
 *  `projects/{project_id_or_number}/locations/{location_id}/entryGroups/{entry_group_id}`.
 */
// const parent = 'abc123'
/**
 *  Required. Entry Link identifier
 *  * Must contain only lowercase letters, numbers and hyphens.
 *  * Must start with a letter.
 *  * Must be between 1-63 characters.
 *  * Must end with a number or a letter.
 *  * Must be unique within the EntryGroup.
 */
// const entryLinkId = 'abc123'
/**
 *  Required. Entry Link resource.
 */
// const entryLink = {}

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

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

async function callCreateEntryLink() {
  // Construct request
  const request = {
    parent,
    entryLinkId,
    entryLink,
  };

  // Run request
  const response = await dataplexClient.createEntryLink(request);
  console.log(response);
}

callCreateEntryLink();

Python

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

如要向 Knowledge 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_entry_link():
    # Create a client
    client = dataplex_v1.CatalogServiceClient()

    # Initialize request argument(s)
    entry_link = dataplex_v1.EntryLink()
    entry_link.entry_link_type = "entry_link_type_value"
    entry_link.entry_references.name = "name_value"
    entry_link.entry_references.type_ = "TARGET"

    request = dataplex_v1.CreateEntryLinkRequest(
        parent="parent_value",
        entry_link_id="entry_link_id_value",
        entry_link=entry_link,
    )

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

    # Handle the response
    print(response)

REST

如要建立具有必要切面的項目連結,請使用 entryLinks.create 方法,並在要求主體中加入切面資料。

為項目連結新增切面

如要使用項目之間的關係資訊來充實中繼資料,請在項目連結中新增切面。

您可以設定項目連結類型,要求特定切面。建立這類項目連結時,必須提供必要切面。

您可以在建立項目連結時新增這些面向,也可以更新現有項目連結,方法如下:

C#

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

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

using Google.Cloud.Dataplex.V1;

public sealed partial class GeneratedCatalogServiceClientSnippets
{
    /// <summary>Snippet for UpdateEntryLink</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 UpdateEntryLinkRequestObject()
    {
        // Create client
        CatalogServiceClient catalogServiceClient = CatalogServiceClient.Create();
        // Initialize request argument(s)
        UpdateEntryLinkRequest request = new UpdateEntryLinkRequest
        {
            EntryLink = new EntryLink(),
            AllowMissing = false,
            AspectKeys = { "", },
        };
        // Make the request
        EntryLink response = catalogServiceClient.UpdateEntryLink(request);
    }
}

Go

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

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


//go:build examples

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.NewCatalogClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

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

Java

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

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

import com.google.cloud.dataplex.v1.CatalogServiceClient;
import com.google.cloud.dataplex.v1.EntryLink;
import com.google.cloud.dataplex.v1.UpdateEntryLinkRequest;
import java.util.ArrayList;

public class SyncUpdateEntryLink {

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

  public static void syncUpdateEntryLink() 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 (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
      UpdateEntryLinkRequest request =
          UpdateEntryLinkRequest.newBuilder()
              .setEntryLink(EntryLink.newBuilder().build())
              .setAllowMissing(true)
              .addAllAspectKeys(new ArrayList<String>())
              .build();
      EntryLink response = catalogServiceClient.updateEntryLink(request);
    }
  }
}

Node.js

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

如要向 Knowledge 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.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Required. Entry Link resource.
 */
// const entryLink = {}
/**
 *  Optional. If set to true and the entry link doesn't exist, the service will
 *  create it.
 */
// const allowMissing = true
/**
 *  Optional. The map keys of the Aspects which the service should modify.
 *  It should be the aspect type reference in the format
 *  `{project_id_or_number}.{location_id}.{aspect_type_id}`.
 *  If this field is left empty, the service treats it as specifying
 *  exactly those Aspects present in the request.
 */
// const aspectKeys = ['abc','def']

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

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

async function callUpdateEntryLink() {
  // Construct request
  const request = {
    entryLink,
  };

  // Run request
  const response = await dataplexClient.updateEntryLink(request);
  console.log(response);
}

callUpdateEntryLink();

Python

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

如要向 Knowledge 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_entry_link():
    # Create a client
    client = dataplex_v1.CatalogServiceClient()

    # Initialize request argument(s)
    entry_link = dataplex_v1.EntryLink()
    entry_link.entry_link_type = "entry_link_type_value"
    entry_link.entry_references.name = "name_value"
    entry_link.entry_references.type_ = "TARGET"

    request = dataplex_v1.UpdateEntryLinkRequest(
        entry_link=entry_link,
    )

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

    # Handle the response
    print(response)

REST

如要更新項目連結,請使用 entryLinks.patch 方法,並在 entryLink 主體中加入切面資料。

請注意,使用切面和項目連結時有下列限制:

  • 不支援選用切面。
  • 不支援資料層面。
  • 不支援自訂類型的面向。
  • 您只能管理系統切面類型定義的必要切面,例如 schema-join。
  • 不支援根據切面內容搜尋項目連結。
  • 不支援匯入或匯出項目連結切面。

管理項目的現有切面

本節說明如何更新及刪除項目的現有切面。

更新切面

您可以編輯自訂項目和系統項目的選用切面。您只能編輯自訂項目的必要切面。

如果是第一方 (1P) 系統項目 (例如 BigQuery 資料表),您可以使用 modifyEntry API 更新切面。這樣一來,您就能使用來源系統的中繼資料更新權限 (例如 BigQuery 資料編輯者 (roles/bigquery.dataEditor))。

控制台

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

    前往「Search」(搜尋) 頁面

  2. 搜尋要更新切面的項目,然後按一下該項目。

項目詳細資料頁面隨即開啟。

  1. 點按「Details」(詳細資料) 分頁標籤。
  2. 在「Aspects」(切面) 部分,展開要更新的切面,然後按一下 「Edit」(編輯)。
  3. 在「Edit aspect」(編輯切面) 視窗中,更新必填欄位。
  4. 按一下「儲存」。

gcloud

如要更新項目或項目資料欄的切面,請使用 gcloud dataplex entries update 指令或 gcloud dataplex entries update-aspects。

如要使用 JSON 檔案更新切面,請按照下列步驟操作:

gcloud dataplex entries update-aspects ENTRY_ID \
  --location=LOCATION \
  --entry-group=ENTRY_GROUP_ID \
  --project=PROJECT_ID \
  --aspects=ASPECTS_JSON_FILE

更改下列內容:

  • ENTRY_ID:項目的 ID。
  • LOCATION:項目的位置。
  • ENTRY_GROUP_ID:項目群組的 ID。
  • PROJECT_ID:專案 ID。
  • ASPECTS_JSON_FILE:包含切面圖的 JSON 檔案路徑。

C#

C#

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

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

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

public sealed partial class GeneratedCatalogServiceClientSnippets
{
    /// <summary>Snippet for UpdateEntry</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 UpdateEntryRequestObject()
    {
        // Create client
        CatalogServiceClient catalogServiceClient = CatalogServiceClient.Create();
        // Initialize request argument(s)
        UpdateEntryRequest request = new UpdateEntryRequest
        {
            Entry = new Entry(),
            UpdateMask = new FieldMask(),
            AllowMissing = false,
            DeleteMissingAspects = false,
            AspectKeys = { "", },
        };
        // Make the request
        Entry response = catalogServiceClient.UpdateEntry(request);
    }
}

Go

Go

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

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


//go:build examples

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.NewCatalogClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

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

Java

Java

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

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

import com.google.cloud.dataplex.v1.CatalogServiceClient;
import com.google.cloud.dataplex.v1.Entry;
import com.google.cloud.dataplex.v1.UpdateEntryRequest;
import com.google.protobuf.FieldMask;
import java.util.ArrayList;

public class SyncUpdateEntry {

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

  public static void syncUpdateEntry() 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 (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
      UpdateEntryRequest request =
          UpdateEntryRequest.newBuilder()
              .setEntry(Entry.newBuilder().build())
              .setUpdateMask(FieldMask.newBuilder().build())
              .setAllowMissing(true)
              .setDeleteMissingAspects(true)
              .addAllAspectKeys(new ArrayList<String>())
              .build();
      Entry response = catalogServiceClient.updateEntry(request);
    }
  }
}

Node.js

Node.js

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

如要向 Knowledge 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.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Required. Entry resource.
 */
// const entry = {}
/**
 *  Optional. Mask of fields to update. To update Aspects, the update_mask must
 *  contain the value "aspects".
 *  If the update_mask is empty, the service will update all modifiable fields
 *  present in the request.
 */
// const updateMask = {}
/**
 *  Optional. If set to true and the entry doesn't exist, the service will
 *  create it.
 */
// const allowMissing = true
/**
 *  Optional. If set to true and the aspect_keys specify aspect ranges, the
 *  service deletes any existing aspects from that range that weren't provided
 *  in the request.
 */
// const deleteMissingAspects = true
/**
 *  Optional. The map keys of the Aspects which the service should modify. It
 *  supports the following syntaxes:
 *  * `<aspect_type_reference>` - matches an aspect of the given type and empty
 *  path.
 *  * `<aspect_type_reference>@path` - matches an aspect of the given type and
 *  specified path. For example, to attach an aspect to a field that is
 *  specified by the `schema` aspect, the path should have the format
 *  `Schema.<field_name>`.
 *  * `<aspect_type_reference>@*` - matches aspects of the given type for all
 *  paths.
 *  * `*@path` - matches aspects of all types on the given path.
 *  The service will not remove existing aspects matching the syntax unless
 *  `delete_missing_aspects` is set to true.
 *  If this field is left empty, the service treats it as specifying
 *  exactly those Aspects present in the request.
 */
// const aspectKeys = ['abc','def']

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

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

async function callUpdateEntry() {
  // Construct request
  const request = {
    entry,
  };

  // Run request
  const response = await dataplexClient.updateEntry(request);
  console.log(response);
}

callUpdateEntry();

Python

Python

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

如要向 Knowledge 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_entry():
    # Create a client
    client = dataplex_v1.CatalogServiceClient()

    # Initialize request argument(s)
    entry = dataplex_v1.Entry()
    entry.entry_type = "entry_type_value"

    request = dataplex_v1.UpdateEntryRequest(
        entry=entry,
    )

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

    # Handle the response
    print(response)

小茹

Ruby

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

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

require "google/cloud/dataplex/v1"

##
# Snippet for the update_entry call in the CatalogService 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::CatalogService::Client#update_entry.
#
def update_entry
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::Dataplex::V1::CatalogService::Client.new

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

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

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

REST

如要更新項目或項目資料欄的切面,請使用 entry.patch 方法。

刪除切面

控制台

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

    前往「Search」(搜尋) 頁面

  2. 搜尋要刪除切面的項目,然後按一下該項目。

項目詳細資料頁面隨即開啟。

  1. 點按「Details」(詳細資料) 分頁標籤。
  2. 在「Aspects」(切面) 部分,展開要刪除的切面,然後按一下「Delete」(刪除) 。
  3. 按一下「確認」。

gcloud

如要刪除項目的切面,請使用 gcloud dataplex entries update 指令並加上 --remove-aspects 旗標。

如要刪除項目層級切面,請按照下列步驟操作:

gcloud dataplex entries update ENTRY_ID \
  --location=LOCATION \
  --entry-group=ENTRY_GROUP_ID \
  --project=PROJECT_ID \
  --remove-aspects='ASPECT_TYPE'

如要刪除資料欄層級切面,請按照下列步驟操作:

gcloud dataplex entries update ENTRY_ID \
  --location=LOCATION \
  --entry-group=ENTRY_GROUP_ID \
  --project=PROJECT_ID \
  --remove-aspects='ASPECT_TYPE@Schema.COLUMN_NAME'

更改下列內容:

  • ENTRY_ID:項目的 ID。
  • LOCATION:項目的位置。
  • ENTRY_GROUP_ID:項目群組的 ID。
  • PROJECT_ID:專案 ID。
  • ASPECT_TYPE:完整的切面類型 ID,例如 dataplex-types.global.generic 或 <var>PROJECT_ID</var>.<var>LOCATION</var>.<var>ASPECT_TYPE_ID</var>。
  • COLUMN_NAME:資料欄名稱。

C#

C#

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

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

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

public sealed partial class GeneratedCatalogServiceClientSnippets
{
    /// <summary>Snippet for UpdateEntry</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 UpdateEntryRequestObject()
    {
        // Create client
        CatalogServiceClient catalogServiceClient = CatalogServiceClient.Create();
        // Initialize request argument(s)
        UpdateEntryRequest request = new UpdateEntryRequest
        {
            Entry = new Entry(),
            UpdateMask = new FieldMask(),
            AllowMissing = false,
            DeleteMissingAspects = false,
            AspectKeys = { "", },
        };
        // Make the request
        Entry response = catalogServiceClient.UpdateEntry(request);
    }
}

Go

Go

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

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


//go:build examples

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.NewCatalogClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

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

Java

Java

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

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

import com.google.cloud.dataplex.v1.CatalogServiceClient;
import com.google.cloud.dataplex.v1.Entry;
import com.google.cloud.dataplex.v1.UpdateEntryRequest;
import com.google.protobuf.FieldMask;
import java.util.ArrayList;

public class SyncUpdateEntry {

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

  public static void syncUpdateEntry() 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 (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
      UpdateEntryRequest request =
          UpdateEntryRequest.newBuilder()
              .setEntry(Entry.newBuilder().build())
              .setUpdateMask(FieldMask.newBuilder().build())
              .setAllowMissing(true)
              .setDeleteMissingAspects(true)
              .addAllAspectKeys(new ArrayList<String>())
              .build();
      Entry response = catalogServiceClient.updateEntry(request);
    }
  }
}

Node.js

Node.js

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

如要向 Knowledge 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.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Required. Entry resource.
 */
// const entry = {}
/**
 *  Optional. Mask of fields to update. To update Aspects, the update_mask must
 *  contain the value "aspects".
 *  If the update_mask is empty, the service will update all modifiable fields
 *  present in the request.
 */
// const updateMask = {}
/**
 *  Optional. If set to true and the entry doesn't exist, the service will
 *  create it.
 */
// const allowMissing = true
/**
 *  Optional. If set to true and the aspect_keys specify aspect ranges, the
 *  service deletes any existing aspects from that range that weren't provided
 *  in the request.
 */
// const deleteMissingAspects = true
/**
 *  Optional. The map keys of the Aspects which the service should modify. It
 *  supports the following syntaxes:
 *  * `<aspect_type_reference>` - matches an aspect of the given type and empty
 *  path.
 *  * `<aspect_type_reference>@path` - matches an aspect of the given type and
 *  specified path. For example, to attach an aspect to a field that is
 *  specified by the `schema` aspect, the path should have the format
 *  `Schema.<field_name>`.
 *  * `<aspect_type_reference>@*` - matches aspects of the given type for all
 *  paths.
 *  * `*@path` - matches aspects of all types on the given path.
 *  The service will not remove existing aspects matching the syntax unless
 *  `delete_missing_aspects` is set to true.
 *  If this field is left empty, the service treats it as specifying
 *  exactly those Aspects present in the request.
 */
// const aspectKeys = ['abc','def']

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

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

async function callUpdateEntry() {
  // Construct request
  const request = {
    entry,
  };

  // Run request
  const response = await dataplexClient.updateEntry(request);
  console.log(response);
}

callUpdateEntry();

Python

Python

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

如要向 Knowledge 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_entry():
    # Create a client
    client = dataplex_v1.CatalogServiceClient()

    # Initialize request argument(s)
    entry = dataplex_v1.Entry()
    entry.entry_type = "entry_type_value"

    request = dataplex_v1.UpdateEntryRequest(
        entry=entry,
    )

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

    # Handle the response
    print(response)

小茹

Ruby

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

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

require "google/cloud/dataplex/v1"

##
# Snippet for the update_entry call in the CatalogService 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::CatalogService::Client#update_entry.
#
def update_entry
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::Dataplex::V1::CatalogService::Client.new

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

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

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

REST

如要刪除項目的切面,請使用 entry.patch 方法。

管理項目連結的現有切面

本節說明如何更新項目連結的現有切面。

更新切面

如果是項目連結,您只能更新使用可重複系統切面類型的必要切面。

詳情請參閱「項目連結作業的 IAM 權限」。

REST

如要更新項目連結並加入必要切面,請使用 entryLinks.patch 方法,並在要求主體中加入切面資料。

刪除切面

您無法刪除項目連結的必要切面。

管理切面類型

本節說明如何查看切面類型,以及更新和刪除自訂切面類型。

查看可用切面類型清單

控制台

  1. 前往 Google Cloud 控制台的 Knowledge Catalog「Metadata types」(中繼資料類型) 頁面。

    前往「Metadata types」(中繼資料類型) 頁面

  2. 按一下「Aspect types」(切面類型) 分頁標籤。

這個頁面列出所有可用的 Knowledge Catalog 切面類型。

  1. 如要查看自訂切面類型,請按一下「Custom」(自訂) 分頁標籤。在「Custom」(自訂) 分頁中,「Catalog source」(目錄來源) 欄會顯示資源在 Knowledge Catalog 中的位置。

如要查看系統切面類型,請按一下「System」(系統) 分頁標籤。

如要進一步瞭解自訂和系統切面類型,請參閱本文的「切面類型類別」一節。

  1. 選用:如要查看所選專案中的切面類型清單,請按一下「Custom」(自訂) 分頁標籤,然後將「Show from all projects」(顯示所有專案) 切換鈕設為關閉位置。

「Show from all projects」(顯示所有專案) 切換鈕預設為開啟,清單會列出所選組織的 Knowledge Catalog 資源。

gcloud

如要列出所有可用的切面類型,請使用 gcloud dataplex aspect-types list 指令。

C#

C#

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

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

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

public sealed partial class GeneratedCatalogServiceClientSnippets
{
    /// <summary>Snippet for ListAspectTypes</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 ListAspectTypesRequestObject()
    {
        // Create client
        CatalogServiceClient catalogServiceClient = CatalogServiceClient.Create();
        // Initialize request argument(s)
        ListAspectTypesRequest request = new ListAspectTypesRequest
        {
            ParentAsLocationName = LocationName.FromProjectLocation("[PROJECT]", "[LOCATION]"),
            Filter = "",
            OrderBy = "",
        };
        // Make the request
        PagedEnumerable<ListAspectTypesResponse, AspectType> response = catalogServiceClient.ListAspectTypes(request);

        // Iterate over all response items, lazily performing RPCs as required
        foreach (AspectType 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 (ListAspectTypesResponse page in response.AsRawResponses())
        {
            // Do something with each page of items
            Console.WriteLine("A page of results:");
            foreach (AspectType 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<AspectType> 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 (AspectType 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

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

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


//go:build examples

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.NewCatalogClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &dataplexpb.ListAspectTypesRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/dataplex/apiv1/dataplexpb#ListAspectTypesRequest.
	}
	it := c.ListAspectTypes(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.ListAspectTypesResponse)
	}
}

Java

Java

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

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

import com.google.cloud.dataplex.v1.AspectType;
import com.google.cloud.dataplex.v1.CatalogServiceClient;
import com.google.cloud.dataplex.v1.ListAspectTypesRequest;
import com.google.cloud.dataplex.v1.LocationName;

public class SyncListAspectTypes {

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

  public static void syncListAspectTypes() 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 (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
      ListAspectTypesRequest request =
          ListAspectTypesRequest.newBuilder()
              .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
              .setPageSize(883849137)
              .setPageToken("pageToken873572522")
              .setFilter("filter-1274492040")
              .setOrderBy("orderBy-1207110587")
              .build();
      for (AspectType element : catalogServiceClient.listAspectTypes(request).iterateAll()) {
        // doThingsWith(element);
      }
    }
  }
}

Node.js

Node.js

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

如要向 Knowledge 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.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Required. The resource name of the AspectType location, of the form:
 *  `projects/{project_number}/locations/{location_id}`
 *  where `location_id` refers to a Google Cloud region.
 */
// const parent = 'abc123'
/**
 *  Optional. Maximum number of AspectTypes to return. The service may return
 *  fewer than this value. If unspecified, the service returns at most 10
 *  AspectTypes. The maximum value is 1000; values above 1000 will be coerced
 *  to 1000.
 */
// const pageSize = 1234
/**
 *  Optional. Page token received from a previous `ListAspectTypes` call.
 *  Provide this to retrieve the subsequent page. When paginating, all other
 *  parameters you provide to `ListAspectTypes` must match the call that
 *  provided the page token.
 */
// const pageToken = 'abc123'
/**
 *  Optional. Filter request. Filters are case-sensitive.
 *  The service supports the following formats:
 *  * labels.key1 = "value1"
 *  * labels:key1
 *  * name = "value"
 *  These restrictions can be conjoined with AND, OR, and NOT conjunctions.
 */
// const filter = 'abc123'
/**
 *  Optional. Orders the result by `name` or `create_time` fields.
 *  If not specified, the ordering is undefined.
 */
// const orderBy = 'abc123'

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

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

async function callListAspectTypes() {
  // Construct request
  const request = {
    parent,
  };

  // Run request
  const iterable = dataplexClient.listAspectTypesAsync(request);
  for await (const response of iterable) {
      console.log(response);
  }
}

callListAspectTypes();

Python

Python

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

如要向 Knowledge 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_aspect_types():
    # Create a client
    client = dataplex_v1.CatalogServiceClient()

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

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

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

小茹

Ruby

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

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

require "google/cloud/dataplex/v1"

##
# Snippet for the list_aspect_types call in the CatalogService 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::CatalogService::Client#list_aspect_types.
#
def list_aspect_types
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::Dataplex::V1::CatalogService::Client.new

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

  # Call the list_aspect_types method.
  result = client.list_aspect_types 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::AspectType.
    p item
  end
end

REST

如要列出所有可用的切面類型,請使用 aspectTypes.list 方法。

查看切面類型的詳細資料

控制台

  1. 前往 Google Cloud 控制台的 Knowledge Catalog「Metadata types」(中繼資料類型) 頁面。

    前往「Metadata types」(中繼資料類型) 頁面

  2. 按一下「Aspect types」(切面類型) 分頁標籤。

  3. 如要查看 Knowledge Catalog 切面類型的詳細資料,請按一下該切面類型。切面類型詳細資料頁面隨即開啟,您可以在此查看詳細資料,例如顯示名稱、切面類型 ID、說明、專案 ID、位置、標籤、建立日期和上次修改日期。

    • 如要查看所選切面類型的結構,請按一下「Template」(範本) 分頁標籤。
    • 如要查看最近建立的 10 個相關項目清單,請按一下「Sample entries」(範例項目) 分頁標籤。
    • 如要搜尋所有相關項目,請按一下「在搜尋結果顯示所有相關項目」。只有在至少有一個相關項目時,才會顯示這個按鈕。

gcloud

如要取得切面類型的詳細資料,請使用 gcloud dataplex aspect-types describe 指令。

C#

C#

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

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

using Google.Cloud.Dataplex.V1;

public sealed partial class GeneratedCatalogServiceClientSnippets
{
    /// <summary>Snippet for GetAspectType</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 GetAspectTypeRequestObject()
    {
        // Create client
        CatalogServiceClient catalogServiceClient = CatalogServiceClient.Create();
        // Initialize request argument(s)
        GetAspectTypeRequest request = new GetAspectTypeRequest
        {
            AspectTypeName = AspectTypeName.FromProjectLocationAspectType("[PROJECT]", "[LOCATION]", "[ASPECT_TYPE]"),
        };
        // Make the request
        AspectType response = catalogServiceClient.GetAspectType(request);
    }
}

Go

Go

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

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


//go:build examples

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.NewCatalogClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

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

Java

Java

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

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

import com.google.cloud.dataplex.v1.AspectType;
import com.google.cloud.dataplex.v1.AspectTypeName;
import com.google.cloud.dataplex.v1.CatalogServiceClient;
import com.google.cloud.dataplex.v1.GetAspectTypeRequest;

public class SyncGetAspectType {

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

  public static void syncGetAspectType() 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 (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
      GetAspectTypeRequest request =
          GetAspectTypeRequest.newBuilder()
              .setName(AspectTypeName.of("[PROJECT]", "[LOCATION]", "[ASPECT_TYPE]").toString())
              .build();
      AspectType response = catalogServiceClient.getAspectType(request);
    }
  }
}

Node.js

Node.js

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

如要向 Knowledge 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.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Required. The resource name of the AspectType:
 *  `projects/{project_number}/locations/{location_id}/aspectTypes/{aspect_type_id}`.
 */
// const name = 'abc123'

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

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

async function callGetAspectType() {
  // Construct request
  const request = {
    name,
  };

  // Run request
  const response = await dataplexClient.getAspectType(request);
  console.log(response);
}

callGetAspectType();

Python

Python

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

如要向 Knowledge 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_aspect_type():
    # Create a client
    client = dataplex_v1.CatalogServiceClient()

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

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

    # Handle the response
    print(response)

小茹

Ruby

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

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

require "google/cloud/dataplex/v1"

##
# Snippet for the get_aspect_type call in the CatalogService 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::CatalogService::Client#get_aspect_type.
#
def get_aspect_type
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::Dataplex::V1::CatalogService::Client.new

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

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

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

REST

如要取得切面類型的詳細資料,請使用 aspectTypes.get 方法。

更新自訂切面類型

您可以更新自訂切面類型的顯示名稱、說明、範本欄位和標籤。您無法刪除範本中的現有欄位。

切面類型建立後,即無法更新切面類型 ID 和位置。

控制台

  1. 前往 Google Cloud 控制台的 Knowledge Catalog「Metadata types」(中繼資料類型) 頁面。

    前往「Metadata types」(中繼資料類型) 頁面

  2. 按一下「Aspect types」(切面類型) 分頁標籤。

  3. 按一下要更新的切面類型。

  4. 在「Aspect type details」(切面類型詳細資料) 頁面,按一下「Edit」(編輯)。

  5. 視需要編輯顯示名稱、說明、範本欄位和標籤。

  6. 選用:如要將切面類型中的欄位標示為已淘汰,請按照下列步驟操作:

    1. 在「Template」(範本) 部分,展開欄位。
    2. 選取「已淘汰」。
    3. 在「Deprecation reason」(淘汰原因) 欄位中,輸入淘汰所選欄位的原因。
    4. 按一下「完成」。

    5. 按一下「儲存」。

gcloud

如要更新自訂切面類型,請使用 gcloud dataplex aspect-types update 指令。

C#

C#

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

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

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

public sealed partial class GeneratedCatalogServiceClientSnippets
{
    /// <summary>Snippet for UpdateAspectType</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 UpdateAspectTypeRequestObject()
    {
        // Create client
        CatalogServiceClient catalogServiceClient = CatalogServiceClient.Create();
        // Initialize request argument(s)
        UpdateAspectTypeRequest request = new UpdateAspectTypeRequest
        {
            AspectType = new AspectType(),
            UpdateMask = new FieldMask(),
            ValidateOnly = false,
        };
        // Make the request
        Operation<AspectType, OperationMetadata> response = catalogServiceClient.UpdateAspectType(request);

        // Poll until the returned long-running operation is complete
        Operation<AspectType, OperationMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        AspectType 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<AspectType, OperationMetadata> retrievedResponse = catalogServiceClient.PollOnceUpdateAspectType(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            AspectType retrievedResult = retrievedResponse.Result;
        }
    }
}

Go

Go

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

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


//go:build examples

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.NewCatalogClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &dataplexpb.UpdateAspectTypeRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/dataplex/apiv1/dataplexpb#UpdateAspectTypeRequest.
	}
	op, err := c.UpdateAspectType(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

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

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

import com.google.cloud.dataplex.v1.AspectType;
import com.google.cloud.dataplex.v1.CatalogServiceClient;
import com.google.cloud.dataplex.v1.UpdateAspectTypeRequest;
import com.google.protobuf.FieldMask;

public class SyncUpdateAspectType {

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

  public static void syncUpdateAspectType() 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 (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
      UpdateAspectTypeRequest request =
          UpdateAspectTypeRequest.newBuilder()
              .setAspectType(AspectType.newBuilder().build())
              .setUpdateMask(FieldMask.newBuilder().build())
              .setValidateOnly(true)
              .build();
      AspectType response = catalogServiceClient.updateAspectTypeAsync(request).get();
    }
  }
}

Node.js

Node.js

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

如要向 Knowledge 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.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Required. AspectType Resource
 */
// const aspectType = {}
/**
 *  Required. Mask of fields to update.
 */
// const updateMask = {}
/**
 *  Optional. Only validate the request, but do not perform mutations.
 *  The default is false.
 */
// const validateOnly = true

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

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

async function callUpdateAspectType() {
  // Construct request
  const request = {
    aspectType,
    updateMask,
  };

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

callUpdateAspectType();

Python

Python

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

如要向 Knowledge 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_aspect_type():
    # Create a client
    client = dataplex_v1.CatalogServiceClient()

    # Initialize request argument(s)
    aspect_type = dataplex_v1.AspectType()
    aspect_type.metadata_template.name = "name_value"
    aspect_type.metadata_template.type_ = "type__value"

    request = dataplex_v1.UpdateAspectTypeRequest(
        aspect_type=aspect_type,
    )

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

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

    response = operation.result()

    # Handle the response
    print(response)

小茹

Ruby

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

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

require "google/cloud/dataplex/v1"

##
# Snippet for the update_aspect_type call in the CatalogService 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::CatalogService::Client#update_aspect_type.
#
def update_aspect_type
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::Dataplex::V1::CatalogService::Client.new

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

  # Call the update_aspect_type method.
  result = client.update_aspect_type 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

如要更新自訂切面類型,請使用 aspectTypes.patch 方法。

刪除自訂切面類型

控制台

  1. 前往 Google Cloud 控制台的 Knowledge Catalog「Metadata types」(中繼資料類型) 頁面。

    前往「Metadata types」(中繼資料類型) 頁面

  2. 按一下「Aspect types」(切面類型) 分頁標籤。

  3. 按一下要刪除的切面類型。

  4. 在「Aspect type details」(切面類型詳細資料) 頁面中,按一下「Delete」(刪除)。在系統提示時確認刪除。

gcloud

如要刪除自訂切面類型,請使用 gcloud dataplex aspect-types delete 指令。

C#

C#

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

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

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

public sealed partial class GeneratedCatalogServiceClientSnippets
{
    /// <summary>Snippet for DeleteAspectType</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 DeleteAspectTypeRequestObject()
    {
        // Create client
        CatalogServiceClient catalogServiceClient = CatalogServiceClient.Create();
        // Initialize request argument(s)
        DeleteAspectTypeRequest request = new DeleteAspectTypeRequest
        {
            AspectTypeName = AspectTypeName.FromProjectLocationAspectType("[PROJECT]", "[LOCATION]", "[ASPECT_TYPE]"),
            Etag = "",
        };
        // Make the request
        Operation<Empty, OperationMetadata> response = catalogServiceClient.DeleteAspectType(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 = catalogServiceClient.PollOnceDeleteAspectType(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

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

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


//go:build examples

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.NewCatalogClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

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

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

Java

Java

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

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

import com.google.cloud.dataplex.v1.AspectTypeName;
import com.google.cloud.dataplex.v1.CatalogServiceClient;
import com.google.cloud.dataplex.v1.DeleteAspectTypeRequest;
import com.google.protobuf.Empty;

public class SyncDeleteAspectType {

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

  public static void syncDeleteAspectType() 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 (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
      DeleteAspectTypeRequest request =
          DeleteAspectTypeRequest.newBuilder()
              .setName(AspectTypeName.of("[PROJECT]", "[LOCATION]", "[ASPECT_TYPE]").toString())
              .setEtag("etag3123477")
              .build();
      catalogServiceClient.deleteAspectTypeAsync(request).get();
    }
  }
}

Node.js

Node.js

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

如要向 Knowledge 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.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Required. The resource name of the AspectType:
 *  `projects/{project_number}/locations/{location_id}/aspectTypes/{aspect_type_id}`.
 */
// const name = 'abc123'
/**
 *  Optional. If the client provided etag value does not match the current etag
 *  value, the DeleteAspectTypeRequest method returns an ABORTED error
 *  response.
 */
// const etag = 'abc123'

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

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

async function callDeleteAspectType() {
  // Construct request
  const request = {
    name,
  };

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

callDeleteAspectType();

Python

Python

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

如要向 Knowledge 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_aspect_type():
    # Create a client
    client = dataplex_v1.CatalogServiceClient()

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

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

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

    response = operation.result()

    # Handle the response
    print(response)

小茹

Ruby

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

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

require "google/cloud/dataplex/v1"

##
# Snippet for the delete_aspect_type call in the CatalogService 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::CatalogService::Client#delete_aspect_type.
#
def delete_aspect_type
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::Dataplex::V1::CatalogService::Client.new

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

  # Call the delete_aspect_type method.
  result = client.delete_aspect_type 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

如要刪除現有的自訂切面類型,請使用 aspectTypes.delete 方法。

後續步驟