建立資料產品

本文適用於想要在 Knowledge Catalog (舊稱 Dataplex Universal Catalog) 建立及設定資料產品的資料產品擁有者。

如要進一步瞭解資料產品的架構和重要概念,請參閱「關於資料產品」。

事前準備

建立資料產品前,請先完成下列必要條件。

啟用 Gemini

設定資料資產中的 Gemini 是選用步驟,但強烈建議您在建立第一個資料產品前完成這項操作。

根據預設,建立資料產品時,您必須手動輸入資產的業務說明、技術定義和新手上路文件。啟用 Gemini 整合功能後,Knowledge Catalog 會運用 AI 輔助功能,自動分析結構定義和資料掃描結果,生成下列內容:

  • 業務文件:為資料產品及其個別資料資產產生文件範本和清楚的說明。
  • 洞察資料和查詢範例:根據資產的結構定義版面配置建構可立即使用的查詢範例,讓資料消費者在獲得核准後,立即開始查詢產品。

如果選擇不啟用 Gemini,可以略過這個部分。不過,您必須在建立期間手動提供所有資產中繼資料和查詢範本。

如要進一步瞭解如何啟用 Gemini in BigQuery,請參閱「設定 Gemini in BigQuery」。

啟用 API

啟用 Dataplex 和 BigQuery API。

啟用 API 時所需的角色

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

啟用 API

建立資料資產

確認已建立並填入資料資產 (例如 BigQuery 資料集、資料表和檢視)。

如要進一步瞭解如何建立資料資產,請參閱下列文件:

設定身分

找出或建立要在資料產品中設定的 Google 群組服務帳戶

必要的角色

本節列出下列主要部分所需的最低 IAM 角色:

  • 資料產品擁有者:建立、設定及管理資料產品和相關聯資產的使用者

  • 資料產品消費者:搜尋、查看及要求存取已發布資料產品的使用者

資料產品擁有者所需的角色

如要取得建立及管理資料產品所需的權限,請要求管理員授予您專案的下列 IAM 角色:

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

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

所需權限

如要建立及管理資料產品,您必須具備下列權限:

  • 建立資料產品: 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 資料產品用戶 (dataplex.dataProductsConsumer) 和 Dataplex Catalog 檢視者 (roles/dataplex.catalogViewer)
  • 唯讀存取權,可查看資料產品定義和中繼資料: Dataplex 資料產品檢視者 (dataplex.dataProductsViewer)

建立及設定資料產品

建立資料產品時,需要完成下列高階工作:

  1. 建立資料產品

    這個必要初始步驟需要定義核心詳細資料,例如專屬資料產品名稱、說明、建立資料產品的區域,以及聯絡資料。

  2. 選用:新增素材資源

    在這個階段,您可以選取要納入資料產品的資產。重要限制是資產必須與資料產品本身位於相同區域。一次最多可以新增 10 項資產,一項資料產品最多可以有 50 項資產。

    如需支援的資產清單,請參閱「支援的資產」。

  3. 選用:設定存取權群組和資產權限

    在這個選用階段,您可以建立存取群組,簡化存取控管。這些存取群組是基礎 Google 群組和服務帳戶的別名,方便使用者辨識 (例如 AnalystReader)。接著,選取特定 IAM 角色,並將其對應至特定資產的存取群組,即可指派權限。

  4. 選填:新增合約和切面詳細資料

    在這個階段,您可以附加中繼資料架構,加強管理及資料探索功能。您可以新增合約,正式傳達資料更新頻率,並指定更新頻率、時間和差異門檻等參數。您也可以附加自訂切面,為資料產品提供額外的業務或技術中繼資料。

  5. 選用:新增其他詳細資料

    在最後階段,您會新增 RTF 文件,例如使用者入門指南、業務定義和範例查詢,協助消費者在核准後立即與資料產品互動。

如要建立及設定資料產品,請完成下列各節的步驟:

建立資料產品

控制台

  1. 前往 Google Cloud 控制台的 Knowledge Catalog「資料產品」頁面。

    前往「資料產品」

  2. 點選「建立」

  3. 在「建立資料產品」窗格中,輸入下列詳細資料:

    • 資料產品名稱:輸入資料產品的專屬名稱。
    • 資料產品 ID:這是系統自動產生的專屬 ID。 您可以編輯這個欄位。
    • 專案 ID:這是建立資料產品的專案專屬 ID。瀏覽並選取專案。
    • 區域:選取資料產品的建立區域或多區域。
    • 資料產品圖示:瀏覽並選取圖示,以視覺化方式識別資料產品。您可以視需要決定是否啟用。
    • 說明:輸入資料產品的簡要說明。
    • 聯絡人:提供控管和核准工作流程的聯絡窗口資訊:

      • 資料產品擁有者的電子郵件地址: 輸入資料產品擁有者的電子郵件地址。
      • 資料產品核准者的電子郵件地址:輸入指定核准者的電子郵件地址,負責簽署存取要求或修改。
    • 標籤:新增鍵值標籤,整理資源。這項設定為選用。

  4. 按一下「建立資料產品」

Terraform

如要建立資料產品,請使用 google_dataplex_data_product 資源。

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

provider = google-beta
}

更改下列內容:

  • PROJECT_ID:您 Google Cloud 專案的 ID
  • LOCATION:要建立資料產品的區域
  • DATA_PRODUCT_ID:資料產品的專屬 ID
  • DISPLAY_NAME:資料產品的簡單易懂名稱
  • DESCRIPTION:資料產品的簡要說明
  • EMAIL_IDs:以半形逗號分隔的資料產品擁有者電子郵件地址,例如 ["user1@example.com", "user2@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:專案的 ID Google Cloud
  • 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"

provider = google-beta
}

更改下列內容:

  • 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. 在「存取權群組 ID」欄位中,輸入要指派給這個存取權群組的 Google 群組電子郵件地址

    要求存取權的資料產品消費者會加入對應的 Google 群組,成為成員。

    如要進一步瞭解如何建立 Google 群組,請參閱「在 Google Cloud 控制台中建立及管理 Google 群組」。

  5. 在「存取權群組服務帳戶」欄位中,輸入要指派給這個存取權群組的服務帳戶電子郵件地址。

    如果資料產品用戶要求服務帳戶的存取權,系統會授予「服務帳戶權杖建立者」(roles/iam.serviceAccountTokenCreator) IAM 角色,模擬對應至存取權群組的資料生產者服務帳戶。

    如要進一步瞭解如何建立服務帳戶,請參閱「建立服務帳戶」。

  6. 按一下 [完成]

  7. 如要新增其他存取群組,請按一下「新增存取群組」,然後重複上述步驟。

    每個資料產品最多可新增三個存取群組。

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

provider = google-beta
}

更改下列內容:

  • PROJECT_ID:您 Google Cloud 專案的 ID
  • LOCATION:資料產品所在的區域
  • DATA_PRODUCT_ID:資料產品的專屬 ID
  • DISPLAY_NAME:資料產品的簡單易懂名稱
  • EMAIL_IDs:以半形逗號分隔的資料產品擁有者電子郵件地址,例如 ["user1@example.com", "user2@example.com"]

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@gserviceaccount.com"
        }
    }
    
  • PROJECT_ID:專案的 ID Google Cloud

  • 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"]
}

provider = google-beta
}

更改下列內容:

  • 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:專案的 ID Google Cloud

  • LOCATION:資料產品所在的區域

  • DATA_PRODUCT_ID:資料產品的 ID

  • DATA_ASSET_ID:要設定權限的資產 ID

選填:新增合約和切面詳細資料

您可以為資料產品新增合約和切面。

新增合約

如要建立資料生產者與消費者之間的信任基礎,您可以將合約附加至資料產品。指定重新整理時間和門檻等參數,為消費者提供必要背景資訊,瞭解資料更新時間,以及資料是否符合特定業務需求。

控制台

  1. 在「新增合約和切面詳細資料」窗格中,按一下「新增合約」

  2. 在「Select contract」(選取合約) 欄位中,選取「Refresh cadence」。

  3. 在「頻率」欄位中,選取雙方同意的資料更新或傳送時間表,確保資料從生產者到消費者之間有可預測的流程。例如:Weekly

  4. 在「重新整理時間」欄位中,輸入資料在來源更新後,最晚何時可供消費者使用。例如:23:00 PST

  5. 在「門檻 (以分鐘為單位)」欄位中,輸入可接受的資料傳送延遲時間 (以分鐘為單位)。例如,輸入 30 可將門檻設為 30 分鐘。

  6. 選用:在「Cron schedule」(Cron 排程) 欄位中,輸入定義資料產生和傳送排程的 Cron 運算式,格式為:MINUTE HOUR DAY_OF_MONTH MONTH DAY_OF_WEEK

    可接受的值如下:

    • MINUTE0-59
    • HOUR0-23
    • DAY_OF_MONTH1-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"
    })
  }
}

provider = google-beta
}

更改下列內容:

  • 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:建立構面所在專案的 ID Google Cloud
  • 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 = {}
  }
}

provider = google-beta
}

更改下列內容:

  • 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. 在 RTF 格式編輯器中輸入內容。

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

provider = google-beta
}

更改下列內容:

  • 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 編輯者 (roles/dataplex.dataScanEditor) 或 Dataplex DataScan 管理員 (roles/dataplex.dataScanAdmin)
    • 查看產生的洞察資料:資料產品所在專案的 Dataplex DataScan DataViewer (roles/dataplex.dataScanDataViewer)
  3. 設定跨專案服務代理權限。如果基礎資料資產位於與資料產品專案不同的專案,您必須授予 Knowledge Catalog 服務代理 (P4SA) 存取這些資產的權限: Google Cloud

    1. 如要為資料產品專案產生或擷取服務代理 ID,請執行下列 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 資料編輯者 (roles/bigquery.dataEditor)

      • 資產專案的 BigQuery Studio 管理員 (roles/bigquery.studioAdmin)

如要使用資料洞察產生資料產品的文件和範例查詢,請按照下列步驟操作:

  1. 在「新增其他詳細資料」窗格中,點按「透過 Gemini 生成洞察資料」列,然後點按「生成」

    請稍候幾分鐘,等待洞察資料生成程序完成。

  2. 如要查看生成的內容,請按一下「查看」

  3. 評估生成的內容:

    • 如果內容正確無誤,請按一下「儲存」。這會以預先定義的說明文件範本填入 RTF 編輯器,並在「洞察」部分新增範例查詢。

    • 如果內容不符合預期,請按一下「捨棄」

  4. 按一下「儲存」即可完成設定。

後續步驟