创建数据产品

本文档面向希望在 Knowledge Catalog(以前称为 Dataplex Universal Catalog)中创建和配置数据产品的数据产品所有者。定义这些资源时,请确保其 ID 符合 Knowledge Catalog 资源命名指南

如需详细了解数据产品的架构和关键概念,请参阅数据产品简介

准备工作

在创建数据产品之前,请完成以下前提条件。

启用 Gemini

在创建第一个数据产品之前,您可以选择配置数据资产中的 Gemini,但强烈建议您执行此步骤。

默认情况下,创建数据产品需要您手动输入资产的业务说明、技术定义和初始配置文档。启用 Gemini 集成后,Knowledge Catalog 会利用 AI 辅助功能自动分析您的架构和数据扫描结果,以生成以下内容:

  • 业务文档:为您的数据产品及其各个数据资产生成文档模板和清晰的说明。
  • 分析洞见和查询示例:根据资产的架构布局构建可随时使用的查询示例,让数据使用方在获得批准后立即开始查询产品。

如果您选择不启用 Gemini,可以跳过此部分。不过,您必须在创建时手动提供所有资产元数据和查询模板。

如需详细了解如何在 BigQuery 中启用 Gemini,请参阅设置 Gemini in BigQuery

启用 API

启用 Dataplex API 和 BigQuery API。

启用 API 所需的角色

如需启用 API,您需要拥有 serviceusage.services.enable 权限。如果您创建了项目,则可能已经通过 Owner 角色 (roles/owner) 获得了此权限。否则,您可以通过 Service Usage Admin 角色 (roles/serviceusage.serviceUsageAdmin) 获得此权限。了解如何授予角色

启用 API

创建数据资产

确保已创建并填充数据资产(例如 BigQuery 数据集、表和视图)。

如需详细了解如何创建数据资产,请参阅以下文档:

配置身份

确定或创建要在数据产品中配置的 Google 群组服务账号

所需的角色

本部分概述了以下主要部分所需的最低 IAM 角色:

  • 数据产品所有者:创建、配置和管理数据产品及其关联资产的用户

  • 数据产品使用者:搜索、查看和请求访问已发布数据产品的用户

数据产品所有者所需的角色

如需获得创建和管理数据产品所需的权限,请让管理员向您授予项目的以下 IAM 角色:

  • 拥有创建、更新、删除数据产品、管理数据产品权限以及批准或拒绝数据产品访问请求的完整权限:Dataplex Data Products Admin (roles/dataplex.dataProductsAdmin)
  • 更新和管理权限,以及批准或拒绝数据产品的访问请求:Dataplex Data Products Editor (roles/dataplex.dataProductsEditor)
  • 添加元数据切面(例如 schemaoverviewcontactsqueries): Dataplex Entry and EntryLink Owner (roles/dataplex.entryOwner)
  • 搜索和添加资产:Dataplex Catalog Viewer (roles/dataplex.catalogViewer)
  • 修改系统切面类型(例如 overviewcontactcontractqueries): Dataplex Catalog Editor (roles/dataplex.catalogEditor)
  • 创建或检索数据分析数据扫描,以实现自动化文档编制和数据分析生成: Dataplex DataScan Admin (roles/dataplex.dataScanAdmin)

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

这些预定义角色包含创建和管理数据产品所需的权限。如需查看所需的确切权限,请展开所需权限部分:

所需权限

如需创建和管理数据产品,需要具备以下权限:

  • 创建数据产品: dataplex.dataProducts.create
  • 列出项目中的数据产品: dataplex.dataProducts.list
  • 获取或查看数据产品: dataplex.dataProducts.get
  • 修改现有数据产品: dataplex.dataProducts.update
  • 删除数据产品: dataplex.dataProducts.delete
  • 批准数据产品访问权限请求: dataplex.dataProducts.approve
  • 使用 Knowledge Catalog 搜索数据产品:
    • dataplex.dataProducts.get
    • dataplex.projects.search
  • 创建数据产品访问权限请求: dataplex.dataProducts.get
  • 创建数据资产: dataplex.dataAssets.create
  • 列出数据商品中的数据资产: dataplex.dataAssets.list
  • 获取数据资产: dataplex.dataAssets.get
  • 修改现有数据资产: dataplex.dataAssets.update
  • 删除数据资产: dataplex.dataAssets.delete
  • 创建数据扫描: dataplex.datascans.create
  • 列出所有数据扫描: dataplex.datascans.list
  • 获取数据扫描: dataplex.datascans.get
  • 运行数据扫描: dataplex.datascans.run
  • 修改 overview 系统切面类型: dataplex.entryGroups.useOverviewAspect
  • 修改 refresh cadence 系统切面类型: dataplex.entryGroups.useRefreshCadenceAspect
  • 修改 queries 系统切面类型: dataplex.entryGroups.useQueriesAspect

您也可以使用自定义角色或其他预定义角色来获取这些权限。

数据产品使用方所需的角色

为了让数据产品使用方能够搜索、查看和请求访问数据产品,作为数据产品所有者,您必须确保数据产品可被发现。为此,请向数据产品使用方授予数据产品的以下 IAM 角色:

  • 搜索数据产品并请求访问权限:Dataplex Data Product Consumer (dataplex.dataProductsConsumer) 和 Dataplex Catalog Viewer (roles/dataplex.catalogViewer)
  • 拥有只读权限,可查看数据产品定义和元数据:Dataplex Data Product Viewer (dataplex.dataProductsViewer)

创建和配置数据产品

创建数据产品涉及以下高级别任务:

  1. 创建数据产品

    此初始步骤是强制性的,需要定义核心详细信息,例如唯一的数据产品名称、说明、创建数据产品的区域和联系信息。

  2. 可选:添加资产

    在此阶段,您需要选择要纳入数据产品中的资产。一项关键限制是,资产必须与数据产品本身位于同一区域。每次最多添加 10 项资产,每个数据产品最多可包含 50 项资产。

    如需查看支持的资产列表,请参阅支持的资产

  3. 可选:配置访问权限群组和资产权限

    在此可选阶段,您可以通过创建访问权限群组来简化访问权限控制。这些访问权限群组充当底层 Google 群组和服务账号的用户友好型别名(例如 AnalystReader)。然后,您可以通过选择特定的 IAM 角色并将其映射到特定资产的访问权限群组来分配权限。

  4. 可选:添加合同和切面详情

    在此阶段,您可以通过附加元数据框架来增强治理和数据可发现性。您可以添加合同,以正式传达数据刷新频率,并指定刷新频率、时间安排和方差阈值等参数。您还可以附加自定义切面,为数据产品提供其他业务或技术元数据。

  5. 可选:添加其他详细信息

    在最后这个阶段,您需要添加富文本文档,例如用户入门指南、业务定义和示例查询,以便消费者在获得批准后立即与数据产品互动。

如需创建和配置数据产品,请完成以下各部分中的步骤:

创建数据产品

控制台

  1. 在 Google Cloud 控制台中,前往 Knowledge Catalog 数据产品页面。

    前往“数据产品”

  2. 点击创建

  3. 创建数据产品窗格中,输入以下详细信息:

    • 数据产品名称:为数据产品输入一个独一无二的名称。
    • 数据产品 ID:这是系统自动生成的唯一标识符。 您可以修改此字段。
    • 项目 ID:这是创建数据产品的项目的唯一标识符。浏览并选择相应项目。
    • 区域:选择创建数据产品的区域或多区域。
    • 数据产品图标:浏览并选择一个图标,以便直观地识别数据产品。这是可选操作。
    • 说明:输入数据产品的简要说明。
    • 联系人:提供治理和审批工作流的联系人信息:

      • 数据产品所有者的电子邮件地址: 输入数据产品所有者的电子邮件地址。
      • 数据产品审批人邮箱:输入指定审批人的电子邮件地址,这些审批人负责批准访问请求或修改。
    • 标签:添加键值对标签以整理资源。这是可选操作。

  4. 点击创建数据产品

Terraform

如需创建数据产品,请使用 google_dataplex_data_productIAM 资源。

resource "google_dataplex_data_product" "default" {
  project         = "PROJECT_ID"
  location        = "LOCATION"
  data_product_id = "DATA_PRODUCT_ID"
  display_name    = "DISPLAY_NAME"
  description     = "DESCRIPTION"
  owner_emails    = ["EMAIL_IDs"]

  # Optional: Configures designated approvers for access requests
  access_approval_config {
    approver_emails = ["APPROVER_EMAIL_IDs"]
  }

  # Optional: Base64-encoded icon (Max 3.0MiB)
  icon = "ICON_BASE64_STRING"
}

resource "google_dataplex_data_product_iam_member" "consumer_binding" {
  project         = "PROJECT_ID"
  location        = "LOCATION"
  data_product_id = "DATA_PRODUCT_ID"
  role            = "roles/dataplex.dataProductsConsumer"
  member          = "MEMBER"
}

替换以下内容:

  • PROJECT_ID:您的 Google Cloud 项目的 ID。
  • LOCATION:您要在其中创建数据产品的区域。
  • DATA_PRODUCT_ID:数据产品的唯一 ID。
  • DISPLAY_NAME:数据产品的简单易记的名称。
  • DESCRIPTION:数据产品的简要说明。
  • EMAIL_IDs:数据产品所有者的电子邮件地址(以逗号分隔),例如 ["user1@example.com", "user2@example.com"]
  • APPROVER_EMAIL_IDs:指定审批者的电子邮件地址(以英文逗号分隔),负责批准相应数据产品的访问请求或修改。
  • ICON_BASE64_STRING:表示数据产品的原始 base64 编码图片数据。大小上限为 3.0 MiB。请勿添加数据网址协议前缀。
  • MEMBER:接收使用方角色的用户、服务账号或群组(例如 group:all-analysts@example.com)。

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 GeneratedDataProductServiceClientSnippets
{
    /// <summary>Snippet for CreateDataProduct</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 CreateDataProductRequestObject()
    {
        // Create client
        DataProductServiceClient dataProductServiceClient = DataProductServiceClient.Create();
        // Initialize request argument(s)
        CreateDataProductRequest request = new CreateDataProductRequest
        {
            ParentAsLocationName = LocationName.FromProjectLocation("[PROJECT]", "[LOCATION]"),
            DataProductId = "",
            DataProduct = new DataProduct(),
            ValidateOnly = false,
        };
        // Make the request
        Operation<DataProduct, OperationMetadata> response = dataProductServiceClient.CreateDataProduct(request);

        // Poll until the returned long-running operation is complete
        Operation<DataProduct, OperationMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        DataProduct 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<DataProduct, OperationMetadata> retrievedResponse = dataProductServiceClient.PollOnceCreateDataProduct(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            DataProduct 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.NewDataProductClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &dataplexpb.CreateDataProductRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/dataplex/apiv1/dataplexpb#CreateDataProductRequest.
	}
	op, err := c.CreateDataProduct(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.CreateDataProductRequest;
import com.google.cloud.dataplex.v1.DataProduct;
import com.google.cloud.dataplex.v1.DataProductServiceClient;
import com.google.cloud.dataplex.v1.LocationName;

public class SyncCreateDataProduct {

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

  public static void syncCreateDataProduct() 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 (DataProductServiceClient dataProductServiceClient = DataProductServiceClient.create()) {
      CreateDataProductRequest request =
          CreateDataProductRequest.newBuilder()
              .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
              .setDataProductId("dataProductId1437828576")
              .setDataProduct(DataProduct.newBuilder().build())
              .setValidateOnly(true)
              .build();
      DataProduct response = dataProductServiceClient.createDataProductAsync(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 parent resource where this data product will be created.
 *  Format: projects/{project_id_or_number}/locations/{location_id}
 */
// const parent = 'abc123'
/**
 *  Optional. The ID of the data product to create.
 *  The ID must conform to RFC-1034 and contain only lower-case letters (a-z),
 *  numbers (0-9), or hyphens, with the first character a letter, the last a
 *  letter or a number, and a 63 character maximum. Characters outside of
 *  ASCII are not permitted.
 *  Valid format regex: `^[a-z]([a-z0-9-]{0,61}[a-z0-9])?$`
 *  If not provided, a system generated ID will be used.
 */
// const dataProductId = 'abc123'
/**
 *  Required. The data product to create.
 */
// const dataProduct = {}
/**
 *  Optional. Validates the request without actually creating the data product.
 *  Default: false.
 */
// const validateOnly = true

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

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

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

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

callCreateDataProduct();

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_data_product():
    # Create a client
    client = dataplex_v1.DataProductServiceClient()

    # Initialize request argument(s)
    data_product = dataplex_v1.DataProduct()
    data_product.display_name = "display_name_value"
    data_product.owner_emails = ["owner_emails_value1", "owner_emails_value2"]

    request = dataplex_v1.CreateDataProductRequest(
        parent="parent_value",
        data_product=data_product,
    )

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

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

    response = operation.result()

    # Handle the response
    print(response)

REST

如需创建数据产品,请使用 dataProducts.create 方法。

例如,发送以下 POST 请求:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-d '{"display_name": "DISPLAY_NAME", "owner_emails": ["EMAIL_IDs"], "access_approval_config": { "approver_emails": ["APPROVER_EMAIL_IDs"]} }' \
https://dataplex.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/dataProducts?data_product_id=DATA_PRODUCT_ID

替换以下内容:

  • DISPLAY_NAME:数据产品的简单易记的名称
  • EMAIL_IDs:数据产品所有者的电子邮件地址(以逗号分隔)
  • APPROVER_EMAIL_IDs:负责批准访问请求或修改的指定审批者的电子邮件地址(以逗号分隔)。
  • PROJECT_ID:您的 Google Cloud项目的 ID
  • LOCATION:您要在其中创建数据产品的区域
  • DATA_PRODUCT_ID:数据产品的唯一 ID

可选:添加资产

您可以向数据产品添加各种数据资产,例如 BigQuery 表、视图、数据集和模型。如需查看支持的资产列表,请参阅支持的资产

控制台

  1. 添加资产窗格中,点击 +添加

  2. 搜索并选择要添加到数据产品中的资产。 您选择的资产必须与数据产品位于同一区域。

    如果您拥有必要的权限,则可以通过点击资产来查看资产的元数据。

  3. 如需优化搜索结果,请使用过滤条件

  4. 选择资产后,点击添加

  5. 点击继续

Terraform

如需向数据产品添加数据资产,请使用 google_dataplex_data_product_data_asset 资源。

resource "google_dataplex_data_product_data_asset" "example_asset" {
project         = "PROJECT_ID"
location        = "LOCATION"
data_product_id = "DATA_PRODUCT_ID"
data_asset_id   = "DATA_ASSET_ID"
resource        = "RESOURCE_NAME"
}

替换以下内容:

  • PROJECT_ID:您的 Google Cloud 项目的 ID
  • LOCATION:数据产品所在的区域
  • DATA_PRODUCT_ID:数据产品的 ID
  • DATA_ASSET_ID:相应数据资产在数据产品中的唯一 ID
  • RESOURCE_NAME:数据资产的完整资源名称(例如 //bigquery.googleapis.com/projects/PROJECT_ID/datasets/DATASET_ID/tables/TABLE_ID

C#

C#

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

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

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

public sealed partial class GeneratedDataProductServiceClientSnippets
{
    /// <summary>Snippet for CreateDataAsset</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 CreateDataAssetRequestObject()
    {
        // Create client
        DataProductServiceClient dataProductServiceClient = DataProductServiceClient.Create();
        // Initialize request argument(s)
        CreateDataAssetRequest request = new CreateDataAssetRequest
        {
            ParentAsDataProductName = DataProductName.FromProjectLocationDataProduct("[PROJECT]", "[LOCATION]", "[DATA_PRODUCT]"),
            DataAssetId = "",
            DataAsset = new DataAsset(),
            ValidateOnly = false,
        };
        // Make the request
        Operation<DataAsset, OperationMetadata> response = dataProductServiceClient.CreateDataAsset(request);

        // Poll until the returned long-running operation is complete
        Operation<DataAsset, OperationMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        DataAsset 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<DataAsset, OperationMetadata> retrievedResponse = dataProductServiceClient.PollOnceCreateDataAsset(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            DataAsset 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.NewDataProductClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &dataplexpb.CreateDataAssetRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/dataplex/apiv1/dataplexpb#CreateDataAssetRequest.
	}
	op, err := c.CreateDataAsset(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.CreateDataAssetRequest;
import com.google.cloud.dataplex.v1.DataAsset;
import com.google.cloud.dataplex.v1.DataProductName;
import com.google.cloud.dataplex.v1.DataProductServiceClient;

public class SyncCreateDataAsset {

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

  public static void syncCreateDataAsset() 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 (DataProductServiceClient dataProductServiceClient = DataProductServiceClient.create()) {
      CreateDataAssetRequest request =
          CreateDataAssetRequest.newBuilder()
              .setParent(DataProductName.of("[PROJECT]", "[LOCATION]", "[DATA_PRODUCT]").toString())
              .setDataAssetId("dataAssetId2108984609")
              .setDataAsset(DataAsset.newBuilder().build())
              .setValidateOnly(true)
              .build();
      DataAsset response = dataProductServiceClient.createDataAssetAsync(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 parent resource where this data asset will be created.
 *  Format:
 *  projects/{project_id_or_number}/locations/{location_id}/dataProducts/{data_product_id}
 */
// const parent = 'abc123'
/**
 *  Optional. The ID of the data asset to create.
 *  The ID must conform to RFC-1034 and contain only lower-case letters (a-z),
 *  numbers (0-9), or hyphens, with the first character a letter, the last a
 *  letter or a number, and a 63 character maximum. Characters outside of
 *  ASCII are not permitted.
 *  Valid format regex: `^[a-z]([a-z0-9-]{0,61}[a-z0-9])?$`
 *  If not provided, a system generated ID will be used.
 */
// const dataAssetId = 'abc123'
/**
 *  Required. The data asset to create.
 */
// const dataAsset = {}
/**
 *  Optional. Validates the request without actually creating the data asset.
 *  Defaults to false.
 */
// const validateOnly = true

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

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

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

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

callCreateDataAsset();

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_data_asset():
    # Create a client
    client = dataplex_v1.DataProductServiceClient()

    # Initialize request argument(s)
    data_asset = dataplex_v1.DataAsset()
    data_asset.resource = "resource_value"

    request = dataplex_v1.CreateDataAssetRequest(
        parent="parent_value",
        data_asset=data_asset,
    )

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

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

    response = operation.result()

    # Handle the response
    print(response)

REST

如需向数据产品添加数据资产,请使用 dataAssets.create 方法。

例如,发送以下 POST 请求:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-d '{"resource": "RESOURCE_NAME"}' \
https://dataplex.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/dataProducts/DATA_PRODUCT_ID/dataAssets?data_asset_id=DATA_ASSET_ID

替换以下内容:

  • RESOURCE_NAME:数据资产的完整资源名称(例如 //bigquery.googleapis.com/projects/PROJECT_ID/datasets/DATASET_ID/tables/TABLE_ID
  • PROJECT_ID:您的 Google Cloud 项目的 ID
  • LOCATION:数据产品所在的区域
  • DATA_PRODUCT_ID:数据产品的 ID
  • DATA_ASSET_ID:相应数据资产在数据产品中的唯一 ID

可选:配置访问权限群组和资产权限

配置访问权限群组和资产权限窗格中,您可以创建访问权限群组并为资产分配权限。

配置访问权限群组

控制台

  1. 点击添加访问权限群组

  2. 访问权限群组名称字段中,输入访问权限群组的名称。 例如 Analyst

  3. 访问权限群组说明字段中,输入访问权限群组的说明。

  4. 访问权限群组标识符字段中,输入您要分配给相应访问权限群组的 Google 群组的电子邮件地址

    自行申请访问权限的数据产品使用方会被添加为映射的 Google 群组的成员。

    如需详细了解如何创建 Google 群组,请参阅在 Google Cloud 控制台中创建和管理 Google 群组

  5. 访问权限群组服务账号字段中,输入您要分配给相应访问权限群组的服务账号的电子邮件地址。

    如果数据产品使用方为其服务账号申请访问权限,则会被授予 Service Account Token Creator (roles/iam.serviceAccountTokenCreator) IAM 角色,以模拟映射到相应访问权限群组的数据提供方服务账号。

    如需详细了解如何创建服务账号,请参阅创建服务账号

  6. 点击完成

  7. 如需添加其他访问权限组,请点击添加访问权限组,然后重复上述步骤。

    每个数据产品最多可以添加 3 个访问权限群组。

  8. 点击保存

Terraform

如需为数据产品定义访问组,请使用 google_dataplex_data_product 资源中的 access_groups 嵌套块。

例如,使用以下配置:

resource "google_dataplex_data_product" "example_data_product" {
  project         = "PROJECT_ID"
  location        = "LOCATION"
  data_product_id = "DATA_PRODUCT_ID"
  display_name    = "DISPLAY_NAME"
  owner_emails    = ["EMAIL_IDs"]

  access_groups {
    id           = "analyst" # Internal identifier for configuration
    group_id     = "analyst" # Unique identifier of the access group, should be same as the 'id'
    display_name = "Business Analyst"
    description  = "Access group for regional analysts"
    principal {
      google_group = "analyst-team@example.com"
    }

# Service account principal
  access_groups {
    id           = "scientist"
    group_id     = "scientist"
    display_name = "Data Scientist"
    principal {
      service_account = "SERVICE_ACCOUNT_EMAIL_ADDRESS"
    }
  }
}

替换以下内容:

  • PROJECT_ID:您的 Google Cloud 项目的 ID
  • LOCATION:数据产品所在的区域
  • DATA_PRODUCT_ID:数据产品的唯一 ID
  • DISPLAY_NAME:数据产品的简单易记的名称
  • EMAIL_IDs:数据产品所有者的电子邮件地址(以逗号分隔),例如 ["user1@example.com", "user2@example.com"]
  • SERVICE_ACCOUNT_EMAIL_ADDRESS:服务账号的电子邮件地址

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 GeneratedDataProductServiceClientSnippets
{
    /// <summary>Snippet for UpdateDataProduct</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 UpdateDataProductRequestObject()
    {
        // Create client
        DataProductServiceClient dataProductServiceClient = DataProductServiceClient.Create();
        // Initialize request argument(s)
        UpdateDataProductRequest request = new UpdateDataProductRequest
        {
            DataProduct = new DataProduct(),
            UpdateMask = new FieldMask(),
            ValidateOnly = false,
        };
        // Make the request
        Operation<DataProduct, OperationMetadata> response = dataProductServiceClient.UpdateDataProduct(request);

        // Poll until the returned long-running operation is complete
        Operation<DataProduct, OperationMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        DataProduct 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<DataProduct, OperationMetadata> retrievedResponse = dataProductServiceClient.PollOnceUpdateDataProduct(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            DataProduct 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.NewDataProductClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &dataplexpb.UpdateDataProductRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/dataplex/apiv1/dataplexpb#UpdateDataProductRequest.
	}
	op, err := c.UpdateDataProduct(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.DataProduct;
import com.google.cloud.dataplex.v1.DataProductServiceClient;
import com.google.cloud.dataplex.v1.UpdateDataProductRequest;
import com.google.protobuf.FieldMask;

public class SyncUpdateDataProduct {

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

  public static void syncUpdateDataProduct() 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 (DataProductServiceClient dataProductServiceClient = DataProductServiceClient.create()) {
      UpdateDataProductRequest request =
          UpdateDataProductRequest.newBuilder()
              .setDataProduct(DataProduct.newBuilder().build())
              .setUpdateMask(FieldMask.newBuilder().build())
              .setValidateOnly(true)
              .build();
      DataProduct response = dataProductServiceClient.updateDataProductAsync(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 data product to update.
 *  The data product's `name` field is used to identify the data product to
 *  update.
 */
// const dataProduct = {}
/**
 *  Optional. The list of fields to update.
 *  If this is empty or not set, then all the fields will be updated.
 */
// const updateMask = {}
/**
 *  Optional. Validates the request without actually updating the data product.
 *  Default: false.
 */
// const validateOnly = true

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

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

async function callUpdateDataProduct() {
  // Construct request
  const request = {
    dataProduct,
  };

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

callUpdateDataProduct();

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_data_product():
    # Create a client
    client = dataplex_v1.DataProductServiceClient()

    # Initialize request argument(s)
    data_product = dataplex_v1.DataProduct()
    data_product.display_name = "display_name_value"
    data_product.owner_emails = ["owner_emails_value1", "owner_emails_value2"]

    request = dataplex_v1.UpdateDataProductRequest(
        data_product=data_product,
    )

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

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

    response = operation.result()

    # Handle the response
    print(response)

REST

如需为数据产品配置访问组,请使用 dataProducts.patch 方法。

例如,发送以下 PATCH 请求:

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-d '{"access_groups": ACCESS_GROUPS_MAP}' \
https://dataplex.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/dataProducts/DATA_PRODUCT_ID?update_mask="access_groups"

替换以下内容:

  • ACCESS_GROUPS_MAP:一个 JSON 对象,表示一个映射,其中每个键都是一个访问组 ID,值是一个 AccessGroup 对象。例如:

    {
    "analyst": {
      "id": "analyst",
      "display_name": "Analyst access group",
      "description": "Access group for analysts",
      "principal":
        {
          "google_group": "analyst-team@example.com",
          "service_account": "analyst-svc@"
        }
    }
    
  • PROJECT_ID:您的 Google Cloud项目的 ID

  • LOCATION:数据产品所在的区域

  • DATA_PRODUCT_ID:数据产品的 ID

配置资源权限

配置访问权限群组后,您可以为数据产品中的资产配置权限。

控制台

  1. 资产权限部分,选择要配置权限的资产。您一次最多可以选择 10 项资产并为其配置权限。

  2. 点击配置权限

  3. 选择访问权限群组字段中,选择一个访问权限群组。

  4. 分配 IAM 角色字段中,选择要分配给访问权限群组的 IAM 角色。

    例如,如果您的资源是名为 Sales 的 BigQuery 表,并且您选择了 Analyst 访问权限群组,还为该访问权限群组分配了 BigQuery Metadata Viewer 角色,那么属于 Analyst 访问权限群组的数据产品使用方就拥有对 Sales 表的 BigQuery Metadata Viewer 权限。

    您可以为资产添加多个角色。

  5. 点击配置。相应资产现在会显示其已分配的权限。

  6. 如需为其他资产配置权限,请重复上述步骤。

  7. 点击继续

Terraform

使用 google_dataplex_data_product_data_asset 资源中的 access_group_configs 块,为您的访问组分配特定资产的 IAM 角色。

例如,使用以下配置:

resource "google_dataplex_data_product_data_asset" "example_data_asset" {
project         = "PROJECT_ID"
location        = "LOCATION"
data_product_id = "DATA_PRODUCT_ID"
data_asset_id   = "DATA_ASSET_ID"
resource        = "RESOURCE_NAME"

access_group_configs {
  access_group = "analyst" # Must match the 'id' defined in google_dataplex_data_product
  iam_roles    = ["roles/bigquery.dataViewer"]
}
}

替换以下内容:

  • PROJECT_ID:您的 Google Cloud 项目的 ID
  • LOCATION:数据产品所在的区域
  • DATA_PRODUCT_ID:数据产品的 ID
  • DATA_ASSET_ID:相应数据资产在数据产品中的唯一 ID
  • RESOURCE_NAME:数据资产的完整资源名称(例如 //bigquery.googleapis.com/projects/PROJECT_ID/datasets/DATASET_ID/tables/TABLE_ID

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 GeneratedDataProductServiceClientSnippets
{
    /// <summary>Snippet for UpdateDataAsset</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 UpdateDataAssetRequestObject()
    {
        // Create client
        DataProductServiceClient dataProductServiceClient = DataProductServiceClient.Create();
        // Initialize request argument(s)
        UpdateDataAssetRequest request = new UpdateDataAssetRequest
        {
            DataAsset = new DataAsset(),
            UpdateMask = new FieldMask(),
            ValidateOnly = false,
        };
        // Make the request
        Operation<DataAsset, OperationMetadata> response = dataProductServiceClient.UpdateDataAsset(request);

        // Poll until the returned long-running operation is complete
        Operation<DataAsset, OperationMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        DataAsset 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<DataAsset, OperationMetadata> retrievedResponse = dataProductServiceClient.PollOnceUpdateDataAsset(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            DataAsset 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.NewDataProductClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &dataplexpb.UpdateDataAssetRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/dataplex/apiv1/dataplexpb#UpdateDataAssetRequest.
	}
	op, err := c.UpdateDataAsset(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.DataAsset;
import com.google.cloud.dataplex.v1.DataProductServiceClient;
import com.google.cloud.dataplex.v1.UpdateDataAssetRequest;
import com.google.protobuf.FieldMask;

public class SyncUpdateDataAsset {

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

  public static void syncUpdateDataAsset() 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 (DataProductServiceClient dataProductServiceClient = DataProductServiceClient.create()) {
      UpdateDataAssetRequest request =
          UpdateDataAssetRequest.newBuilder()
              .setDataAsset(DataAsset.newBuilder().build())
              .setUpdateMask(FieldMask.newBuilder().build())
              .setValidateOnly(true)
              .build();
      DataAsset response = dataProductServiceClient.updateDataAssetAsync(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 data asset to update.
 *  The data asset's `name` field is used to identify the data asset to update.
 */
// const dataAsset = {}
/**
 *  Optional. The list of fields to update.
 *  If this is empty or not set, then all the fields will be updated.
 */
// const updateMask = {}
/**
 *  Optional. Validates the request without actually updating the data asset.
 *  Defaults to false.
 */
// const validateOnly = true

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

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

async function callUpdateDataAsset() {
  // Construct request
  const request = {
    dataAsset,
  };

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

callUpdateDataAsset();

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_data_asset():
    # Create a client
    client = dataplex_v1.DataProductServiceClient()

    # Initialize request argument(s)
    data_asset = dataplex_v1.DataAsset()
    data_asset.resource = "resource_value"

    request = dataplex_v1.UpdateDataAssetRequest(
        data_asset=data_asset,
    )

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

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

    response = operation.result()

    # Handle the response
    print(response)

REST

如需为数据产品中的资源配置权限,请使用 dataAssets.patch 方法。

例如,发送以下 PATCH 请求:

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-d '{"access_group_configs": ACCESS_GROUP_CONFIGS_MAP}' \
https://dataplex.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/dataProducts/DATA_PRODUCT_ID/dataAssets/DATA_ASSET_ID?update_mask="access_group_configs"

替换以下内容:

  • ACCESS_GROUP_CONFIGS_MAP:一个 JSON 对象,表示一个映射,其中每个键都是一个访问组 ID,值是一个 AccessGroupConfig 对象。例如:

    {
    "analyst": {
      iam_roles: ["roles/bigquery.dataViewer"]
      }
    }
    
  • PROJECT_ID:您的 Google Cloud项目的 ID

  • LOCATION:数据产品所在的区域

  • DATA_PRODUCT_ID:数据产品的 ID

  • DATA_ASSET_ID:您要配置权限的资产的 ID

可选:添加合同和切面详情

您可以为数据产品添加合同和方面。

添加合同

为了在数据提供方和使用方之间建立信任基础,您可以为数据产品附加合同。通过指定刷新时间和阈值等参数,您可以为消费者提供必要的背景信息,以便他们了解数据何时更新以及是否满足其特定业务需求。

控制台

  1. 添加合同和切面详情窗格中,点击添加合同

  2. 选择合同字段中,选择 Refresh cadence

  3. 频率字段中,选择一个商定的时间表,用于确定数据更新或交付的频率,确保从数据提供方到数据使用方的可预测流程。例如 Weekly

  4. 刷新时间字段中,输入数据在其来源处更新时以及可供消费者使用时的最大可接受时间。例如 23:00 PST

  5. 阈值(以分钟为单位)字段中,输入可接受的数据传送延迟时间(以分钟为单位)。例如,输入 30 可将阈值设置为 30 分钟。

  6. 可选:在 Cron 时间表字段中,输入一个 cron 表达式,用于定义数据生成和交付的时间表,格式为:MINUTE HOUR DAY_OF_MONTH MONTH DAY_OF_WEEK

    接受的值如下:

    • MINUTE: 0-59
    • HOUR: 0-23
    • DAY_OF_MONTH: 1-31
    • MONTH1-31JAN-DEC
    • DAY_OF_WEEK0-6SUN-SAT

    例如,0 8 * * 1-5 在工作日(周一至周五)上午 8:00 运行。

  7. 点击保存

REST

合同以数据产品上的方面为模型。 如需为数据产品添加 Refresh Cadence 合同,请使用 entries.patch 方法。

例如,发送以下 PATCH 请求:

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-d \
'{
  "aspects": {
    "dataplex-types.global.refresh-cadence": {
      "aspectType": "projects/dataplex-types/locations/global/aspectTypes/refresh-cadence",
      "data": {
        "frequency": "REFRESH_FREQUENCY"
      }
    }
  }
}' \
"https://dataplex.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/entryGroups/@dataplex/entries/projects/DATA_PRODUCT_PROJECT_NUMBER/locations/DATA_PRODUCT_LOCATION/dataProducts/DATA_PRODUCT_ID?updateMask=aspects"

替换以下内容:

  • REFRESH_FREQUENCY:商定的时间表,用于确定数据更新或交付的频率,确保从数据提供方到数据使用方的可预测流程。例如 Weekly
  • PROJECT_ID:发出 API 调用的 Google Cloud 项目的 ID
  • LOCATION:您要调用的 Knowledge Catalog 服务端点的区域(例如 us-central1
  • DATA_PRODUCT_PROJECT_NUMBER:数据产品资源所在的项目编号
  • DATA_PRODUCT_LOCATION:数据产品资源的位置
  • DATA_PRODUCT_ID:数据产品的 ID

Terraform

合同以数据产品上的方面为模型。 如需管理合同,您必须管理基础 Knowledge Catalog 条目。由于 Terraform 不会自动发现现有方面,因此您必须先导入 google_dataplex_entry

如需导入条目,请使用以下命令:

terraform import google_dataplex_entry.data_product_metadata "projects/DATA_PRODUCT_PROJECT_NUMBER/locations/LOCATION/entryGroups/@dataplex/entries/projects/DATA_PRODUCT_PROJECT_NUMBER/locations/LOCATION/dataProducts/DATA_PRODUCT_ID"

Terraform 配置:

resource "google_dataplex_entry" "data_product_metadata" {
project        = "DATA_PRODUCT_PROJECT_NUMBER"
location       = "LOCATION"
entry_group_id = "@dataplex"
entry_id       = "projects/DATA_PRODUCT_PROJECT_NUMBER/locations/LOCATION/dataProducts/DATA_PRODUCT_ID"
entry_type     = "projects/655216118709/locations/global/entryTypes/data-product"

aspects {
  aspect_key = "655216118709.global.refresh-cadence"
  aspect {
    data = jsonencode({
      frequency = "REFRESH_FREQUENCY"
    })
  }
}
}

替换以下内容:

  • DATA_PRODUCT_PROJECT_NUMBER:数据产品资源所在的项目编号
  • LOCATION:您要调用的 Knowledge Catalog 服务端点的区域(例如 us-central1
  • DATA_PRODUCT_ID:数据产品的 ID
  • REFRESH_FREQUENCY:商定的时间表,用于确定数据更新或交付的频率,确保从数据提供方到数据使用方的可预测流程。例如 Weekly

如需了解有关导入流程的一般信息,请参阅 Terraform 导入文档

添加切面

使用切面通过可重复使用的结构化元数据来丰富数据产品。这些模板为数据生产者提供了一种标准化的方式来传达数据产品的质量和适用性,从而改进治理并帮助消费者确定产品是否满足其业务需求。

如需为数据产品添加切面,请按以下步骤操作:

控制台

  1. 添加合同和切面详情窗格中,点击 + 添加切面

  2. 选择切面类型字段中,从列表中搜索并选择一个切面类型。例如 Geo context

  3. 点击保存

REST

如需为数据产品添加切面,请使用 entries.patch 方法。

例如,发送以下 PATCH 请求:

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-d \
'{
  "aspects": {
    "ASPECT_PROJECT_ID.ASPECT_LOCATION.ASPECT_NAME": {
      "aspectType": "projects/ASPECT_PROJECT_ID/locations/ASPECT_LOCATION/aspectTypes/ASPECT_NAME",
      "data": {}
    }
  }
}' \
"https://dataplex.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/entryGroups/@dataplex/entries/projects/DATA_PRODUCT_PROJECT_NUMBER/locations/DATA_PRODUCT_LOCATION/dataProducts/DATA_PRODUCT_ID?updateMask=aspects"

替换以下内容:

  • ASPECT_PROJECT_ID:创建了方面的 Google Cloud项目的 ID
  • ASPECT_LOCATION:创建方面所在的 Knowledge Catalog 服务端点的区域(例如 us-central1
  • ASPECT_NAME:您要附加到数据产品的方面的名称
  • PROJECT_ID:发出 API 调用的 Google Cloud 项目的 ID
  • LOCATION:您要调用的 Knowledge Catalog 服务端点的区域(例如 us-central1
  • DATA_PRODUCT_PROJECT_NUMBER:数据产品资源所在的项目编号
  • DATA_PRODUCT_LOCATION:数据产品资源的位置
  • DATA_PRODUCT_ID:数据产品的 ID

Terraform

如需管理方面,您必须管理基础 Knowledge Catalog 条目。 由于 Terraform 不会自动发现现有方面,因此您必须先导入 google_dataplex_entry

如需导入条目,请使用以下命令:

terraform import google_dataplex_entry.data_product_metadata "projects/DATA_PRODUCT_PROJECT_NUMBER/locations/LOCATION/entryGroups/@dataplex/entries/projects/DATA_PRODUCT_PROJECT_NUMBER/locations/LOCATION/dataProducts/DATA_PRODUCT_ID"

Terraform 配置:

resource "google_dataplex_entry" "data_product_metadata" {
project        = "DATA_PRODUCT_PROJECT_NUMBER"
location       = "LOCATION"
entry_group_id = "@dataplex"
entry_id       = "projects/DATA_PRODUCT_PROJECT_NUMBER/locations/LOCATION/dataProducts/DATA_PRODUCT_ID"
entry_type     = "projects/655216118709/locations/global/entryTypes/data-product"

aspects {
  aspect_key = "ASPECT_PROJECT_NUMBER.ASPECT_LOCATION.ASPECT_NAME"
  aspect {
    data = {}
  }
}
}

替换以下内容:

  • DATA_PRODUCT_PROJECT_NUMBER:数据产品资源所在的项目编号
  • LOCATION:您要调用的 Knowledge Catalog 服务端点的区域(例如 us-central1
  • DATA_PRODUCT_ID:数据产品的 ID
  • ASPECT_PROJECT_NUMBER:创建方面的 Google Cloud 项目编号
  • ASPECT_LOCATION:创建方面所在的 Knowledge Catalog 服务端点的区域(例如 us-central1
  • ASPECT_NAME:您要附加到数据产品的方面的名称

如需了解有关导入流程的一般信息,请参阅 Terraform 导入文档

可选:添加其他详细信息

您可以为数据产品添加文档和查询示例,以提供必要的背景信息、业务逻辑说明和用户指南。在 Knowledge Catalog 中,文档通过 overview 系统方面进行管理。

您可以手动创建此文档,也可以使用 Knowledge Catalog 数据洞见自动生成此文档。

手动添加文档和示例查询

控制台

如需为数据产品添加文档,请按以下步骤操作:

  1. 添加其他详细信息窗格中,点击文档旁边的 修改

  2. 在富文本编辑器中输入内容。

  3. 点击保存

如需为数据产品添加示例查询,请按以下步骤操作:

  1. 添加其他详细信息窗格中,点击查询建议部分中的 添加查询

  2. 输入示例查询。

  3. 点击保存

新创建的数据产品会显示在 Knowledge Catalog 的数据产品页面上。

REST

文档以数据产品上的方面为模型。 如需添加文档,请使用 entries.patch 方法。

例如,发送以下 PATCH 请求:

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-d \
'{
  "aspects": {
    "dataplex-types.global.overview": {
      "aspectType": "projects/dataplex-types/locations/global/aspectTypes/overview",
      "data": {
        "content": "DOCUMENTATION"
      }
    }
  }
}' \
"https://dataplex.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/entryGroups/@dataplex/entries/projects/DATA_PRODUCT_PROJECT_NUMBER/locations/DATA_PRODUCT_LOCATION/dataProducts/DATA_PRODUCT_ID?updateMask=aspects"

替换以下内容:

  • PROJECT_ID:发出 API 调用的 Google Cloud 项目的 ID
  • LOCATION:您要调用的 Knowledge Catalog 服务端点的区域(例如 us-central1
  • DATA_PRODUCT_PROJECT_NUMBER:数据产品资源所在的项目编号
  • DATA_PRODUCT_LOCATION:数据产品资源的位置
  • DATA_PRODUCT_ID:数据产品的 ID
  • DOCUMENTATION:您要附加到数据产品的内容

Terraform

文档以数据产品上的方面为模型。 如需管理文档,您必须管理基础 Knowledge Catalog 条目。由于 Terraform 不会自动发现现有方面,因此您必须先导入 google_dataplex_entry

如需导入条目,请使用以下命令:

terraform import google_dataplex_entry.data_product_metadata "projects/DATA_PRODUCT_PROJECT_NUMBER/locations/LOCATION/entryGroups/@dataplex/entries/projects/DATA_PRODUCT_PROJECT_NUMBER/locations/LOCATION/dataProducts/DATA_PRODUCT_ID"

Terraform 配置:

resource "google_dataplex_entry" "data_product_metadata" {
project        = "DATA_PRODUCT_PROJECT_NUMBER"
location       = "LOCATION"
entry_group_id = "@dataplex"
entry_id       = "projects/DATA_PRODUCT_PROJECT_NUMBER/locations/LOCATION/dataProducts/DATA_PRODUCT_ID"
entry_type     = "projects/655216118709/locations/global/entryTypes/data-product"

aspects {
  aspect_key = "655216118709.global.overview"
  aspect {
    data = jsonencode({
      content = "DOCUMENTATION"
    })
  }
}
}

替换以下内容:

  • DATA_PRODUCT_PROJECT_NUMBER:数据产品资源所在的项目编号
  • LOCATION:您要调用的 Knowledge Catalog 服务端点的区域(例如 us-central1
  • DATA_PRODUCT_ID:数据产品的 ID
  • DOCUMENTATION:您要附加到数据产品的内容

如需了解有关导入流程的一般信息,请参阅 Terraform 导入文档

使用数据洞见生成自动化文档和示例查询

在使用 Gemini 生成文档和示例查询之前,请完成以下前提条件:

  1. 在您创建数据产品的项目中启用 Gemini for Google Cloud API。

  2. 授予特定于数据分析的用户角色:请让管理员向您的身份授予数据产品项目的以下角色和权限:

    • 生成和管理数据分析:数据产品所在项目的 Dataplex DataScan Editor (roles/dataplex.dataScanEditor) 或 Dataplex DataScan Administrator (roles/dataplex.dataScanAdmin)
    • 查看生成的分析洞见:数据产品所在项目的 Dataplex DataScan DataViewer (roles/dataplex.dataScanDataViewer)
  3. 配置跨项目服务代理权限。如果您的底层数据资产位于与数据产品项目不同的 Google Cloud 项目中,您必须向知识目录服务代理 (P4SA) 授予对这些资产的访问权限:

    1. 如需为数据产品项目生成或检索服务代理标识符,请运行以下 Google Cloud CLI 命令:

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

      DATA_PRODUCT_PROJECT_ID 替换为数据产品所在的Google Cloud 项目 ID。

    2. 在每个包含资产的外部项目中,向数据产品项目的服务代理授予以下角色:

      • 对底层表和数据集具有 BigQuery Data Editor (roles/bigquery.dataEditor) 权限

      • 资产项目的 BigQuery Studio Admin (roles/bigquery.studioAdmin)

如需使用数据洞见为数据产品生成文档和示例查询,请按以下步骤操作:

  1. 添加其他详细信息窗格中,点击使用 Gemini 生成数据洞见栏,然后点击生成

    等待几分钟,让数据洞见生成过程完成。

  2. 如需查看生成的内容,请点击查看

  3. 评估生成的内容:

    • 如果内容准确无误,请点击保存。这会使用预定义的文档模板填充富文本编辑器,并将示例查询添加到数据洞见部分。

    • 如果内容不符合预期,请点击舍弃

  4. 点击保存以最终确定。

后续步骤