管理切面并丰富元数据

借助 Knowledge Catalog(以前称为 Dataplex Universal Catalog)中的切面和切面类型,您可以向条目和条目链接添加结构化元数据,以描述数据资产及其关系。此上下文可提高数据可发现性,并帮助您对敏感信息(例如个人身份信息 [PII])进行分类,以应用数据质量或访问权限政策。

如需详细了解元数据概念,请参阅 Knowledge Catalog 中的元数据简介。如果您是首次使用 Knowledge Catalog 元数据,请参阅向 BigQuery 表添加元数据或创建和使用业务术语库快速入门。

什么是切面类型?

切面类型是可重复使用的资源,提供用于定义切面的相关元数据字段的 JSON 模板。例如,对于合规性信息,您可以定义一个切面类型,其中包含 PII 分类和 GDPR 合规性字段。创建自定义切面类型时,您必须指定符合 Knowledge Catalog 资源命名准则的 ID。

切面类型的类别

切面类型分为自定义切面类型和系统切面类型:

自定义切面类型

您在 Knowledge Catalog 中创建的切面类型称为自定义切面类型。

自定义切面类型可以是全球性的,也可以是区域级的:

  • 全球切面类型:可用于为任何区域中的条目创建切面。如果您需要将相同的结构应用于多个区域中的条目,请选择 global 切面类型,因为您只需定义一次。由于全球切面类型的定义会复制到所有区域,因此如果切面类型架构本身包含敏感信息,或者需要对所有元数据组件实施严格的数据驻留,则此选项可能不适合。
  • 区域切面类型:只能用于为与切面类型位于同一区域的条目创建切面。例如,在 us-central1 中创建的切面类型只能与 us-central1 中的条目搭配使用。如果某种切面类型仅与特定区域中的条目相关,或者为了确保切面类型定义位于所选区域内(这有助于满足数据主权和合规性要求),请选择区域位置。如果您使用区域切面类型,但需要在多个区域中使用相同的结构,则必须在每个区域中创建和管理单独的切面类型定义。

您可以在特定区域位置(例如 us-central1)创建自定义切面类型,也可以将其创建为 global 资源。切面类型的位置会影响其适用范围,并决定可与其搭配使用的条目。

如需了解详情,请参阅项目和位置限制条件。

系统切面类型

Knowledge Catalog 提供、使用和管理的切面类型称为系统切面类型。系统切面类型始终是全球性的,因此可以在任何区域中使用。系统切面类型存储在项目编号为 655216118709 的 Google 管理的项目中。例如 projects/655216118709/locations/global/aspectTypes/schema。

每个系统定义的切面类型、条目类型和条目链接类型都有自己的 IAM 权限。如需了解详情,请参阅系统切面类型、条目类型和条目链接类型的 IAM 权限。

系统切面类型进一步分为可重复使用和受限两类。下表介绍了系统切面类型的类别,以及 Knowledge Catalog 为每个类别提供的切面类型列表:

系统切面类型的类别 说明 Knowledge Catalog 提供的切面类型
可重复使用的系统切面类型 您可以使用这些切面类型来创建或修改切面。
  • contacts
  • data-profile
  • data-quality-scorecard
  • generic
  • graph-profile
  • guidelines
  • overview
  • schema-join
  • schema
  • storage
  • usage
受限的系统切面类型 Knowledge Catalog 会管理这些切面类型。
您可以读取这些切面类型下的切面,但无法在这些切面类型下创建或修改切面。
包括但不限于:
  • analytics-hub
  • aspecttype-aspect
  • bigquery-dataset
  • bigquery-table
  • cloudsql-database
  • cloudsql-instance
  • cloudsql-table
  • entrygroup-aspect
  • entrytype-aspect
  • sensitive-data-protection-profile
  • storage-bucket
  • storage-folder

自定义切面类型和 Gemini in BigQuery

Gemini 上下文检索边界:Gemini in BigQuery 会根据标准架构定义、表限制条件以及表或列说明字段来生成 SQL 和进行数据推理。Knowledge Catalog 中用户定义的自定义切面类型存储在目录平面中,用于治理、搜索和 API 检索,但不会动态注入到 Gemini 的上下文提示检索流水线中。

建议的最佳实践

为确保 Gemini in BigQuery 能够看到业务逻辑、语义上下文或开发者备注,请直接在表和列说明字段中、标准 overview 方面中或使用业务术语库术语记录这些信息。

如需了解详情,请参阅将 Knowledge Catalog 与 BigQuery 搭配使用。

什么是切面?

利用切面,您可以捕获条目或条目链接中的元数据,以提供有意义的上下文。您可以使用切面来存储以下类型的元数据:

  • 业务元数据:提供业务上下文,例如数据分类。例如,受监管的行业需要保护分布式数据系统中的 PII,例如姓名、地址和由政府签发的身份证件号码。对分布式数据资产进行编目后,您可以将数据分类为 PII,然后对数据应用数据质量或访问政策。

  • 技术元数据:条目或条目链接的技术详细信息,包括:

    • 对于条目:数据资产本身的详细信息,例如其架构。
    • 对于条目链接:数据资产之间关系的详细信息,例如联接详细信息。
  • 数据派生的元数据:根据数据本身生成的信息,例如 BigQuery 表中的统计信息。

切面是父级条目资源的组成部分,而不是单独的独立资源。修改切面会更新包含该切面的条目。如需跟踪这些修改,您可以订阅元数据更改 Feed。

方面放置和目标级别

每个切面都是切面类型模板的一个实例,该模板定义了您必须填充的字段,例如 {"pii_classification": "confidential", "gdpr_compliant": true}。您可以将切面应用于整个表、单个表列或条目链接。您可以应用切面的位置以及切面可以出现的次数取决于目标资源类型:

目标资源 支持的级别 基数上限
条目数 条目级或列级 在条目级别,每个切面类型最多只能有一个切面。允许在不同列中为每个切面类型设置多个切面。
条目链接 仅限关联级别 每个链接的每个切面类型最多只能有一个切面。

切面类别

切面分为必需切面和可选切面:

必需切面

必需的切面是指在创建条目或条目链接时必须使用的切面。此类切面由条目类型或条目链接类型定义。属于特定类型的所有资源必须始终具有该类型定义的所有必需切面。

Knowledge Catalog 会管理系统条目所需的切面(例如架构)。

请注意以下几点:

  • 您只能将必需的切面与条目相关联,而不能与条目列相关联。

  • 您无法从条目或条目链接中删除必需的切面。

  • 您可以读取系统条目的必需切面,但无法修改它们。

  • 数据切面不能是必需切面。

可选切面

您可以将可选切面与条目或条目列相关联。您可以在创建条目时填充可选切面,也可以稍后通过更新条目来填充。

请注意以下几点:

  • 填充可选切面后,您可以将其删除。

  • 条目链接仅支持必需切面。

数据切面

某些切面包含从条目的底层数据派生的信息,而不是有关条目的元数据。这些切面称为数据切面。例如,数据分析扫描或数据质量扫描的结果包含从数据本身派生的统计信息,因此被归类为数据方面。

属于数据切面的系统切面类型包括:

准备工作

在创建和管理方面类型及切面之前,请完成本部分中所述的任务。

所需的角色

如需获得创建和管理切面类型及切面所需的权限,请让您的管理员为您授予资源的以下 IAM 角色:

  • 拥有 Knowledge Catalog 中的元数据资源(包括切面类型和数据切面)的整套权限:Dataplex Catalog Admin (roles/dataplex.catalogAdmin)
  • 在 Knowledge Catalog 中创建和管理元数据资源,包括切面类型和数据切面:Dataplex Catalog Editor (roles/dataplex.catalogEditor)
  • 拥有自定义切面类型的整套权限(除了使用切面类型创建或修改条目的权限):Dataplex Aspect Type Owner (roles/dataplex.aspectTypeOwner)
  • 查看切面类型以及与其关联的 IAM 政策:Dataplex Catalog Viewer (roles/dataplex.catalogViewer)
  • 使用切面类型创建和修改具有相应切面的条目:Dataplex Aspect Type User (roles/dataplex.aspectTypeUser)
  • 添加一些系统切面类型的切面,例如 schema、schema-join、overview、contacts:Dataplex Entry and EntryLink Owner (roles/dataplex.entryOwner)

如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。

您也可以通过自定义角色或其他预定义角色来获取所需的权限。

如需了解详情,请参阅 Knowledge Catalog IAM 角色。

启用 API

在 Knowledge Catalog 项目中启用 Dataplex API。如果您使用的是新 Google Cloud 项目或已启用 BigQuery API 的项目,则 Dataplex API 默认处于启用状态。

启用 API

创建自定义切面类型

控制台

  1. 在 Google Cloud 控制台中,前往 Knowledge Catalog 元数据类型页面。

    前往“元数据类型”

  2. 点击切面类型 > 自定义标签页。

  3. 点击创建切面类型。

  4. 在创建切面类型窗口中,输入以下内容:

    1. 可选:在显示名称字段中,输入切面类型的名称。
    2. 在切面类型 ID 字段中,输入切面类型的唯一 ID。
    3. 可选:在说明字段中,输入切面类型的说明。
    4. 在位置字段中,为切面类型选择一个位置。创建切面类型后,您无法修改其位置。 如需了解选择全球位置与区域位置的影响,请参阅自定义切面类型部分。
  5. 可选:为切面类型定义模板。

    在模板部分中,点击添加字段。在新字段部分中,输入以下内容:

    1. 在名称字段中,输入一个名称。
    2. 可选:在显示名称字段中,输入一个显示名称。
    3. 可选:在说明字段中,输入说明。
    4. 在类型字段中,为该字段选择一种数据类型。根据您的选择,系统会显示下一组字段和选项:

      • 如果您选择了文本作为数据类型,请按照以下步骤操作:

        1. 在文本类型字段中,选择文本类型。
        2. 在文本值字段中,提供文本字段的提示。为此,请点击添加值,然后输入提示。您可以为一个文本字段添加多个提示。
        3. 点击完成。
      • 如果您选择了枚举作为数据类型,请添加枚举值:

        1. 点击添加枚举值。
        2. 在值字段中,输入一个枚举值。您可以添加多个枚举值。
        3. 点击完成。
      • 如果您选择了数组作为数据类型,请在数组项部分中,定义要在数组中显示的项的类型:

        1. 点击添加数组项。
        2. 在名称字段中,输入数组项的名称。
        3. 可选:在显示名称字段中,输入数组项的显示名称。
        4. 可选:在说明字段中,输入数组项的说明。
        5. 在类型字段中,为数组项选择一种数据类型。

          系统会根据您的选择显示下一组字段和选项。它们与本部分其他位置针对文本、枚举、映射、数组和记录数据类型描述的选项类似。

        6. 点击完成。

      • 如果您选择了映射作为数据类型,请在映射值部分中,定义要在映射中显示的值的类型:

        1. 点击添加映射值。
        2. 在名称字段中,输入映射的名称。
        3. 可选:在显示名称字段中,输入映射的显示名称。
        4. 可选:在说明字段中,输入映射的说明。
        5. 在类型字段中,为映射选择一种数据类型。

          系统会根据您的选择显示下一组字段和选项。它们与本部分其他位置针对文本、枚举、映射、数组和记录数据类型描述的选项类似。

        6. 点击完成。

      • 如果您选择了记录作为数据类型,请输入以下内容:

        1. 在记录 ID 字段中,输入一个唯一 ID,其他记录字段可以使用该 ID 引用此记录。请参阅本文档的使用记录 ID 和记录引用字段的示例部分。
        2. 可选:如果您想从此模板中添加对其他记录的引用,请使用记录引用字段。创建切面类型后,您无法修改此字段。请参阅本文档的使用记录 ID 和记录引用字段的示例部分。
        3. 在记录字段部分中,您可以定义具有多个嵌套字段的复杂对象。为此,请点击添加记录字段项,然后指定以下内容:

        4. 在名称字段中,输入记录字段的名称。

        5. 可选:在显示名称字段中,输入记录字段的显示名称。

        6. 可选:在说明字段中,输入记录字段的说明。

        7. 在类型字段中,选择一种数据类型。

          系统会根据您的选择显示下一组字段和选项。它们与本部分前面针对文本、枚举、映射、数组和记录数据类型描述的选项类似。

        8. 点击完成。

    5. 如需将相应字段设为此类型的切面的必填字段,请选择为必填项。如需详细了解必需的切面和可选切面,请参阅本文档的切面类别部分。

    6. 点击完成。

    7. 如需添加多个字段,请点击添加字段,然后重复执行上述步骤。

  6. 可选:在标签部分中,为资源添加键值对形式的任意标签:

    1. 点击添加标签。
    2. 在键字段中,输入一个键。
    3. 在值字段中,输入该键的值。
    4. 如需添加更多标签,请点击添加标签,然后重复上述步骤。
  7. 点击保存。

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

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”和“记录引用”字段的示例

您可以使用记录 ID 和记录引用字段进行递归引用。以下示例展示了如何使用这些字段:

假设一个名为 Employee 的切面类型,其中包含以下字段:

  • 名称(类型:Text)
  • 开始日期(类型:Date & time)
  • 标识(类型:Text)
  • 当前地址(类型:Record)
  • 永久地址(类型:Record)

两个地址字段(当前地址和永久地址)的数据类型均为 Record。为避免重复,您可以在定义这些字段时设置记录 ID 和记录引用 值。

定义当前地址字段时,您可以将记录 ID 指定为 address-field。对于永久地址,您可以为记录引用指定相同的值 (address-field)。例如:

  • 名称(类型:Text)
  • 开始日期(类型:Date & time)
  • 标识(类型:Text)
  • 当前地址(类型:Record,记录 ID:address-field)
  • 永久地址(类型:Record,记录引用:address-field)

这样一来,您便无需重复其他地址的字段。

向条目添加切面

创建自定义切面类型后,您可以创建该类型的切面。如需向条目添加切面,您必须更新该条目,因为切面存储在条目中。

请注意以下几点:

  • 您可以向条目或条目列添加切面。
  • 您只能修改自定义条目的必需切面。您无法删除必需的切面。
  • 您可以修改和删除自定义条目及系统条目的可选切面。

控制台

  1. 在 Google Cloud 控制台中,前往 Knowledge Catalog 搜索页面。

    转到搜索

  2. 搜索要向其添加切面的条目,然后点击该条目。系统会打开条目详情页面。

  3. 如需向条目添加切面,请按照以下步骤操作:

    1. 点击详情标签页。
    2. 如需向条目添加必需的切面或可选切面,请在切面部分中,针对相应类别点击 添加。
      如果所选条目的条目类型未定义必需的切面,则您无法添加必需的切面。
    3. 搜索并选择您要添加的切面。
    4. 在添加切面窗口中,输入相应字段的值。
    5. 点击保存。

    6. 如需向条目列添加切面,请按照以下步骤操作:

    7. 在条目详情页面上,点击架构标签页。

    8. 选择要向其添加切面的列。

    9. 点击添加切面。

    10. 搜索并选择您要添加的切面。

    11. 在添加切面窗口中,输入相应字段的值。

    12. 点击保存。

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

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 组织中。

附加可重复使用的系统切面类型的切面

您可以将可重复使用的系统切面类型的切面附加到条目。

您可以在 Google Cloud 控制台中修改可重复使用的切面类型的切面,具体取决于其结构。 Google Cloud 控制台不支持修改包含嵌套字段的切面类型。您必须使用 gcloud 命令行工具或 REST API 来附加或更新此类型的切面。

数据质量计分卡

数据质量计分卡是一个方面,用于提供数据质量摘要,通常基于数据质量扫描或其他流程。您可以将数据质量统计信息摘要图表附加到条目,以提供自定义数据质量信息。为此,请附加系统定义的类型 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)。

运行附加切面的命令时,该命令会替换该特定切面的所有现有数据。例如,如果您使用显示得分为 90 的新文件更新得分为 80 的记分卡,则 80 将被覆盖。它不会合并数据。

如需附加数据质量统计信息,请按以下步骤操作:

gcloud

如需更新条目的切面,请使用 gcloud dataplex entries update-aspects 命令。

  1. 创建一个包含以下内容的 JSON 文件 (dq-aspect.json)。

      {
        "dataplex-types.global.data-quality-scorecard": {
          "data": {
            "score": 0.8,
            "status": "PASS",
            "dimensions": [
              {
                "name": "completeness",
                "score": 0.9,
                "status": "PASS"
              },
              {
                "name": "uniqueness",
                "score": 0.7,
                "status": "FAIL"
              }
            ],
            "columns": [
              {
                "name": "col1",
                "score": 0.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

其他可重复使用的切面类型

以下系统切面类型也可供使用。您可以使用与数据质量记分卡相同的 gcloud 或 REST API 方法来附加这些标签。对于没有嵌套字段的切面类型(例如 generic),您可以使用控制台。

  • 通讯录。使用 contacts 切面类型分配所有权或管理权。这些字段包括:

    • identities(数组):联系人列表。每个联系人均包含:
      • role(字符串):联系人的角色(例如 owner、steward、producer 或 admin)。
      • name(字符串):联系人的姓名。
      • id(字符串):联系人的邮箱或 ID。

    创建 payload.json 文件,如下所示:

     {
       "aspects": {
         "dataplex-types.global.contacts": {
           "data": {
             "identities": [
               {
                 "role": "steward",
                 "name": "Jane Doe",
                 "id": "jane.doe@example.com"
               }
             ]
           }
         }
       }
     }
    
  • 数据分析。使用 data-profile 切面类型捕获数据分析结果。如需了解详情,请参阅数据分析简介。

    这些字段包括:

    • sourceDataInfo(记录):有关为生成分析而扫描的源数据的信息。
      • scope(枚举):分析文件的范围(PREVIEW、SAMPLED 或 ALL)。PREVIEW 值对应于轻量级分析扫描的结果。
      • scannedRows(整数):扫描的行数。
      • samplingPercentage(双精度):所用的抽样百分比。
    • fields(映射):列名称与其数据分析的映射,包括 uniqueness、nullness、topN 值等指标,以及 numeric、string、datetime 和 array 列的类型特定统计信息。

    创建 payload.json 文件,如下所示:

     {
       "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
            }
          }
             }
           }
         }
       }
     }}
    

  • 宽泛字词。对通用条目信息使用 generic 切面类型。这些字段包括:

    • type(字符串):用于存储用户指定类型的自由格式字段。
    • system(字符串):自定义条目的系统。

    创建 payload.json 文件,如下所示:

    {
      "aspects": {
        "dataplex-types.global.generic": {
          "data": {
            "type": "custom-type",
            "system": "custom-system"
          }
        }
      }
    }
    
  • 概览。使用 overview 切面类型提供富文本说明。这些字段包括:

    • content(字符串):条目概览,支持 HTML 格式。
    • links(数组):源系统链接的列表。每个链接都包含:
      • url(字符串):链接的网址。
      • title(字符串):链接的标题。

    创建 payload.json 文件,如下所示:

    {
      "aspects": {
        "dataplex-types.global.overview": {
          "data": {
            "content": "This is a <b>rich text</b> description.",
          "links": [
            {
              "url": "https://example.com",
              "title": "Example Link"
            }
          ]
        }
      }
    }}
    
  • 架构。使用 schema 切面类型来描述数据结构。

    • fields(数组):架构字段列表。这些字段包括:
      • name(字符串):字段的名称。
      • dataType(字符串):字段的数据类型。
      • metadataType(枚举):元数据类型(例如 STRING、BOOLEAN)。
      • mode(枚举):字段的模式(NULLABLE、REQUIRED、REPEATED)。
      • description(字符串):字段的说明。

    创建 payload.json 文件,如下所示:

    {
      "aspects": {
        "dataplex-types.global.schema": {
          "data": {
            "fields": [
            {
              "name": "id",
              "dataType": "string",
              "metadataType": "STRING",
              "mode": "REQUIRED"
            }
          ]
        }
      }
    }}
    
  • 使用情况。使用 usage 切面类型跟踪使用情况指标。这些字段包括:

    • metrics(数组):用量指标列表。每个指标都包含:
      • name(字符串):指标的名称(例如 views、reads)。
      • timeSeries(数组):时序数据列表。每项内容都包含:
        • interval(字符串):汇总时间间隔(例如 30d)。
        • value(整数):汇总值。
    • refreshTime(日期时间):上次刷新指标的时间。

    创建 payload.json 文件,如下所示:

    {
      "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 Data Editor [roles/bigquery.dataEditor])。

控制台

  1. 在 Google Cloud 控制台中,前往 Knowledge Catalog 搜索页面。

    转到搜索

  2. 搜索要更新其切面的条目,然后点击该条目。

系统会打开条目详情页面。

  1. 点击详情标签页。
  2. 在切面部分中,展开要更新的切面,然后点击 修改。
  3. 在修改切面窗口中,更新必填字段。
  4. 点击保存。

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

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 搜索页面。

    转到搜索

  2. 搜索要删除其切面的条目,然后点击该条目。

系统会打开条目详情页面。

  1. 点击详情标签页。
  2. 在切面部分中,展开要删除的切面,然后点击 删除。
  3. 点击确认。

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

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 元数据类型页面。

    前往“元数据类型”

  2. 点击切面类型标签页。

此页面列出了所有可用的 Knowledge Catalog 切面类型。

  1. 如需查看自定义切面类型,请点击自定义标签页。在自定义标签页中,目录来源列会显示资源在 Knowledge Catalog 中的位置。

如需查看系统切面类型,请点击系统标签页。

如需详细了解自定义切面类型和系统切面类型,请参阅本文档的切面类型的类别部分。

  1. 可选:如需查看所选项目中的切面类型列表,请点击自定义标签页,然后点击显示所有项目中的切面类型切换开关,将其切换到关闭位置。

显示所有项目中的条目组切换开关默认处于开启状态,并且该列表包含所选组织中的 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

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 元数据类型页面。

    前往“元数据类型”

  2. 点击切面类型标签页。

  3. 如需查看 Knowledge Catalog 切面类型的详细信息,请点击该切面类型。系统会打开切面类型详情页面,您可以在其中查看显示名称、切面类型 ID、说明、项目 ID、位置、标签、创建日期和上次修改日期等详细信息。

    • 如需查看所选切面类型的结构,请点击模板标签页。
    • 如需查看最近创建的 10 个相关条目的列表,请点击条目示例标签页。
    • 如需搜索所有相关条目,请点击在搜索结果中显示所有相关条目。仅当至少存在一个相关条目时,才会显示此按钮。

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

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 元数据类型页面。

    前往“元数据类型”

  2. 点击切面类型标签页。

  3. 点击要更新的切面类型。

  4. 在切面类型详细信息页面上,点击修改。

  5. 根据需要修改显示名称、说明、模板字段和标签。

  6. 可选:如需将切面类型中的某个字段标记为已弃用,请按照以下步骤操作:

    1. 在模板部分中,展开相应字段。
    2. 选择已弃用。
    3. 在弃用原因字段中,输入弃用所选字段的原因。
    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

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 元数据类型页面。

    前往“元数据类型”

  2. 点击切面类型标签页。

  3. 点击要删除的切面类型。

  4. 在切面类型详细信息页面上,点击删除。在系统提示时确认。

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

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

后续步骤