管理切面并丰富元数据

元数据对于整理和了解数据资产至关重要。例如,受监管的行业需要保护个人身份信息 (PII),例如姓名、地址和政府签发的身份证号码。此类数据可能出现在分布式数据系统的多个实例中。Dataplex Universal Catalog 可帮助您快速发现和编目分布式数据资产。然后,您可以将数据归类为 PII。

通过为数据条目添加有意义的上下文,您可以让数据更易于发现且更有用。Dataplex Universal Catalog 通过以下方式实现上下文:

  • 切面类型:用于定义相关数据的 JSON 模板。例如,对于合规性信息,您可能需要提供个人身份信息分类和 GDPR 合规性。
  • 切面:切面类型的实例。例如,{"pii_classification": "confidential", "gdpr_compliant": true}。您可以将切面应用于整个表或单个表列。

对数据进行分类后,您可以对数据应用数据质量或访问政策。

如需了解详情,请参阅 Dataplex Universal Catalog 中的元数据管理简介

切面

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

  • 业务元数据:提供业务上下文,例如数据分类。

  • 技术元数据:数据资产的技术详细信息,例如其架构。

  • 数据派生元数据:根据数据本身生成的信息,例如 BigQuery 表中的统计信息。

切面被视为条目资源的一部分,而不是单独的资源。修改切面时,涉及修改包含该切面的条目。

您可以在条目级层指定用于描述条目的切面,也可以在列级层指定用于描述条目中列的切面。

每个切面都是切面类型的一个实例。切面类型用于为其切面定义模板。每个切面类型都包含一组字段。创建切面时,您必须为这些字段提供值。

对于给定的条目,每个切面类型最多只能有一个与该条目关联的切面。每个切面类型可以有多个与条目列关联的切面。

切面类别

切面分为以下几类:

  • 必需的切面:创建条目时必须使用的切面。此类切面由给定条目的条目类型定义。属于某个条目类型的所有条目都必须始终具有该条目类型定义的所有必需切面。

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

    请注意以下几点:

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

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

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

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

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

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

数据切面

切面可以包含从数据中派生的信息,例如数据分析或示例查询的结果。这些切面称为数据切面

切面类型

切面类型是可重复使用的资源,可为切面提供模板。

切面类型的类别

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

自定义切面类型

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

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

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

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

系统切面类型

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

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

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

准备工作

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

所需的角色

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

  • 拥有 Dataplex Universal Catalog 中的元数据资源(包括切面类型和数据切面)的整套权限:Dataplex Catalog Admin (roles/dataplex.catalogAdmin)
  • 在 Dataplex Universal 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)
  • 添加一些系统切面类型的切面,例如 schemaoverviewcontactsDataplex Entry and EntryLink Owner (roles/dataplex.entryOwner)

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

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

如需了解详情,请参阅 Dataplex Universal Catalog IAM 角色

启用 API

在 Dataplex Universal Catalog 项目中启用 Dataplex API。

启用该 API

创建自定义切面类型

控制台

  1. 在 Google Cloud 控制台中,前往 Dataplex Universal 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#

在尝试此示例之前,请按照 Dataplex Universal Catalog 快速入门:使用客户端库中的 C# 设置说明进行操作。如需了解详情,请参阅 Dataplex Universal Catalog C# API 参考文档

如需向 Dataplex Universal Catalog 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为本地开发环境设置身份验证

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

public sealed partial class 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

在尝试此示例之前,请按照 Dataplex Universal Catalog 快速入门:使用客户端库中的 Go 设置说明进行操作。如需了解详情,请参阅 Dataplex Universal Catalog Go API 参考文档

如需向 Dataplex Universal Catalog 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为本地开发环境设置身份验证


package main

import (
	"context"

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

func main() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := dataplex.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

在尝试此示例之前,请按照 Dataplex Universal Catalog 快速入门:使用客户端库中的 Java 设置说明进行操作。如需了解详情,请参阅 Dataplex Universal Catalog Java API 参考文档

如需向 Dataplex Universal 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();
    }
  }
}

Python

Python

在尝试此示例之前,请按照 Dataplex Universal Catalog 快速入门:使用客户端库中的 Python 设置说明进行操作。如需了解详情,请参阅 Dataplex Universal Catalog Python API 参考文档

如需向 Dataplex Universal Catalog 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为本地开发环境设置身份验证

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


def sample_create_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

在尝试此示例之前,请按照 Dataplex Universal Catalog 快速入门:使用客户端库中的 Ruby 设置说明进行操作。如需了解详情,请参阅 Dataplex Universal Catalog Ruby API 参考文档

如需向 Dataplex Universal 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记录引用 值。

定义