使用自訂管道匯入中繼資料

本文說明如何使用中繼資料匯入 API 方法和您自己的管道,將中繼資料從第三方系統匯入 Dataplex Universal Catalog。Dataplex Universal Catalog 中繼資料包含項目及其切面。

如果您想改用 Google Cloud管理的協調管道 擷取及匯入中繼資料,建議使用管理的連線管道。 透過受管理連線管道,您可以自備連接器,擷取中繼資料並以可做為中繼資料匯入 API 方法輸入內容的格式 (中繼資料匯入檔案) 產生輸出內容。然後使用 Workflows 自動化調度管理管道工作。

您可以執行下列類型的中繼資料匯入作業:

  • 完整同步處理項目,並累加匯入項目各方面資料。支援自訂項目。
  • 僅限增量匯入構面。支援屬於自訂項目和系統項目的層面。如果是自訂項目,您可以修改選填和必填的各個方面。如果是系統項目,你可以修改選填項目。

高階步驟

如要使用中繼資料匯入 API 匯入中繼資料,請按照下列高階步驟操作:

  1. 確定工作範圍。

    此外,也請瞭解 Dataplex Universal Catalog 如何套用比較邏輯,以及項目和切面的同步模式。

  2. 建立一或多個中繼資料匯入檔案,定義要匯入的資料。

  3. 將中繼資料匯入檔案儲存在 Cloud Storage 值區中。

  4. 執行中繼資料匯入工作。

本頁的步驟假設您已熟悉 Dataplex Universal Catalog 中繼資料概念,包括項目群組、項目類型和切面類型。詳情請參閱「關於 Dataplex Universal Catalog 中的中繼資料管理」。

事前準備

匯入中繼資料前,請先完成本節中的工作。

必要的角色

為確保 Dataplex Universal Catalog 服務帳戶具備存取 Cloud Storage bucket 的必要權限,請管理員授予該服務帳戶 bucket 的「Storage 物件檢視者」(roles/storage.objectViewer) IAM 角色和 storage.buckets.get 權限。

如要取得管理中繼資料匯入作業所需的權限,請要求管理員授予下列 IAM 角色:

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

您或許也能透過自訂角色或其他預先定義的角色,取得必要權限。

建立 Google Cloud 資源

準備下列 Google Cloud 資源:

  1. 為要匯入的項目建立項目群組
  2. 建立切面類型,以匯入切面。
  3. 為要匯入的項目建立項目類型
  4. 如果執行的只是層面中繼資料工作,請為要匯入的層面建立項目
  5. 建立 Cloud Storage bucket,儲存中繼資料匯入檔案。

中繼資料匯入工作的元件

匯入中繼資料時,請考量中繼資料工作的下列元件:

  • 工作範圍:要納入工作中的項目群組、項目類型和切面類型。
  • 同步處理模式:工作中的項目和層面更新方式。
  • 中繼資料匯入檔案:定義要為工作中的項目和層面設定的值。您可以在同一個中繼資料工作中提供多個中繼資料匯入檔案。將檔案儲存在 Cloud Storage 中。
  • 比較邏輯:Dataplex Universal Catalog 如何判斷要修改哪些項目和層面。

工作範圍

工作範圍會定義要納入中繼資料匯入工作的項目群組、項目類型和切面類型。匯入中繼資料時,您可以修改屬於作業範圍內資源的項目和層面。

如要定義工作範圍,請遵循下列規範:

  • 項目群組:指定要納入工作的一或多個項目群組。 這項工作只會修改屬於這些項目群組的項目和層面。 項目群組和工作必須位於相同地區。

  • 項目類型:指定要納入工作的一或多個項目類型。這項工作只會修改屬於這些項目類型的項目和切面。項目類型的位置必須與工作位置相符,或項目類型必須是全域。

  • 構面類型:指定要納入工作的一或多個構面類型。這項工作只會修改屬於這些切面類型的切面。 切面類型的位置必須與工作地點相符,或切面類型必須是全域。

工作範圍必須包含中繼資料匯入檔案中指定的所有項目類型和切面類型。

建立中繼資料工作時,請指定工作範圍。

同步處理模式

同步模式會指定如何更新中繼資料匯入工作中的項目和層面。你為項目和層面提供同步模式。視要匯入的資源而定,系統支援下列同步模式組合。

目標 項目同步模式 層面同步模式 結果
匯入項目及其相關層面 FULL INCREMENTAL

系統會修改工作範圍內的所有項目。

如果 Dataplex Universal Catalog 中有項目,但中繼資料匯入檔案未包含該項目,執行中繼資料工作時,系統就會刪除該項目。

只有在中繼資料匯入檔案的 updateMask 欄位和 aspectKeys 欄位中包含對該層面的參照時,系統才會修改該層面。請參閱匯入項目的結構

僅匯入層面 NONE INCREMENTAL

如果切面屬於工作範圍,且中繼資料匯入檔案在 aspectKeys 欄位中包含切面參照,系統就會修改切面。請參閱「匯入項目的結構」。

不屬於作業範圍內項目的其他中繼資料不會修改。

建立中繼資料工作時,請指定同步模式。

中繼資料匯入檔案

中繼資料匯入檔案是您要修改的項目和層面集合。這個物件會定義要為這些項目和層面所屬的所有欄位設定的值。您必須先準備檔案,才能執行中繼資料匯入工作。

請遵守下列一般準則:

  • 您可以在同一個中繼資料工作中提供多個中繼資料匯入檔案。
  • 執行完整項目同步中繼資料工作時,檔案中提供的項目會完全取代工作範圍內所有資源的現有項目。也就是說,您必須為工作中的所有項目提供值,而不只是要新增或更新的值。如要取得專案中的目前項目清單做為起點,請使用 entries.list API 方法

  • 您必須在執行中繼資料作業時提供中繼資料匯入檔案。如要刪除工作範圍內所有現有資料,請提供空白的中繼資料匯入檔案。

  • 檔案中包含的所有項目和切面都必須屬於您在工作範圍中定義的項目群組、項目類型和切面類型。

請參閱下列章節的詳細指南,建立中繼資料匯入檔案。

檔案結構

中繼資料匯入檔案中的每一行都包含一個 JSON 物件,對應至一個匯入項目。匯入項目是物件,用於說明要修改的項目值及其附加的層面。

您可以在單一中繼資料匯入檔案中提供多個匯入項目。不過,請勿在同一項中繼資料工作中,重複提供相同的匯入項目。使用換行字元 (0x0a) 分隔每個匯入項目。

中繼資料匯入檔案中,每個匯入項目之間都有換行字元,看起來會像以下範例:

{ "entry": { "name": "entry 1", #Information about entry 1 }
{ "entry": { "name": "entry 2", #Information about entry 2 }

匯入項目的結構

中繼資料匯入檔案中的每個匯入項目都可以包含下列欄位 (請參閱 ImportItem)。 下列範例已加入換行符號,方便閱讀,但儲存檔案時,請只在每個匯入項目後加入換行符號。單一匯入項目的欄位之間不得有斷行。

{
  "entry": {
    "name": "ENTRY_NAME",
    "entryType": "ENTRY_TYPE",
    "entrySource": {
      "resource": "RESOURCE",
      "system": "SYSTEM",
      "platform": "PLATFORM",
      "displayName": "DISPLAY_NAME",
      "description": "DESCRIPTION",
      "createTime": "ENTRY_CREATE_TIMESTAMP",
      "updateTime": "ENTRY_UPDATE_TIMESTAMP"
    },
    "aspects": {
      "ASPECT": {
        "data": {
          "KEY": "VALUE"
        },
        "aspectSource": {
          "createTime": "ASPECT_CREATE_TIMESTAMP",
          "updateTime": "ASPECT_UPDATE_TIMESTAMP"
        }
      },
      # Additional aspect maps
    },
    "parentEntry": "PARENT_ENTRY",
    "fullyQualifiedName": "FULLY_QUALIFIED_NAME"
  },
  "updateMask": "UPDATE_MASK_FIELDS",
  "aspectKeys": [
    "ASPECT_KEY",
    # Additional aspect keys
  ],
}

更改下列內容:

  • entry:項目及其附加層面的相關資訊。 在僅匯入切面的中繼資料工作中,Dataplex Universal Catalog 會忽略項目的所有選用欄位,切面對應除外。

    • ENTRY_NAME:項目的相對資源名稱,格式為 projects/PROJECT_ID_OR_NUMBER/locations/LOCATION_ID/entryGroups/ENTRY_GROUP_ID/entries/ENTRY_ID
    • ENTRY_TYPE:用於建立這個項目的項目類型相對資源名稱,格式為 projects/PROJECT_ID_OR_NUMBER/locations/LOCATION_ID/entryTypes/ENTRY_TYPE_ID
    • entrySource:來源系統中與項目代表的資料資源相關的資訊:
      • RESOURCE:來源系統中的資源名稱。
      • SYSTEM:來源系統的名稱。
      • PLATFORM:包含來源系統的平台。
      • DISPLAY_NAME:簡單易懂的顯示名稱。
      • DESCRIPTION:項目的說明。
      • ENTRY_CREATE_TIMESTAMP:項目在來源系統中建立的時間。
      • ENTRY_UPDATE_TIMESTAMP:項目在來源系統中更新的時間。
    • aspects:附加至項目的切面。aspect 物件及其資料稱為「層面地圖」。

      • ASPECT:附加至項目的層面。請根據附加至項目的層面,採用下列其中一種格式:

        • 如果該層面直接附加至項目,請以 PROJECT_ID_OR_NUMBER.LOCATION_ID.ASPECT_TYPE_ID 格式提供該層面類型的相對資源名稱。
        • 如果該層面附加至項目的路徑,請以 PROJECT_ID_OR_NUMBER.LOCATION_ID.ASPECT_TYPE_ID@PATH 格式提供層面類型的路徑。
      • KEYVALUE:切面的內容,根據切面類型中繼資料範本而定。內容必須採用 UTF-8 編碼。欄位大小上限為 120 KB。即使是空白字典,也必須提供 data

      • ASPECT_CREATE_TIMESTAMP:在來源系統中建立該層面的時間。

      • ASPECT_UPDATE_TIMESTAMP:在來源系統中更新該層面的時間。

    • PARENT_ENTRY:父項項目的資源名稱。

    • FULLY_QUALIFIED_NAME:項目的名稱,可供外部系統參照。請參閱「完整名稱」。

  • UPDATE_MASK_FIELDS:要更新的欄位,路徑與 Entry 資源相關。請以半形逗號分隔各個欄位。

    在完整項目同步工作期間,Dataplex Universal Catalog 會納入可修改項目所有欄位的路徑,包括切面。建立或重新建立項目時,系統會忽略 updateMask 欄位。

    在僅限層面的中繼資料作業中,請將這個值設為 aspects

  • ASPECT_KEY:要修改的層面。支援下列語法:

    • ASPECT_TYPE_REFERENCE:與直接附加至項目的切面切面類型相符。
    • ASPECT_TYPE_REFERENCE@PATH:符合切面類型和指定路徑。
    • ASPECT_TYPE_REFERENCE@*:比對所有路徑的切面類型。
    • *@PATH:比對指定路徑上的所有面向類型。

    ASPECT_TYPE_REFERENCE 替換為對構面類型的參照,格式為 PROJECT_ID_OR_NUMBER.LOCATION_ID.ASPECT_TYPE_ID

    在完整項目同步作業中,如果將這個欄位留空,系統會視為指定項目中存在的確切方面。Dataplex Universal Catalog 會隱含地為項目的所有必要切面新增鍵。

檔案相關規定

中繼資料匯入檔案必須符合下列規定:

  • 檔案必須採用 JSON Lines 格式,也就是以換行符號分隔的 JSON 檔案。使用換行字元 (0x0a) 分隔每個匯入項目。
  • 檔案必須使用 UTF-8 字元編碼。
  • 支援的副檔名為 .jsonl.json
  • 每個中繼資料匯入檔案的大小不得超過 1 GiB。中繼資料工作中的所有資料總大小上限為 3 GB。包括與工作相關聯的所有檔案和中繼資料。
  • 您在檔案中指定的項目類型和切面類型,必須屬於中繼資料工作的範圍。
  • 檔案必須上傳至 Cloud Storage bucket。請勿將檔案儲存到名為 CLOUD_STORAGE_URI/deletions/ 的資料夾。

比較邏輯

Dataplex Universal Catalog 會比較中繼資料匯入檔案中的值和時間戳記,以及專案中的值和時間戳記,判斷要修改哪些項目和切面。

從高層級來看,當中繼資料匯入檔案中至少有一項建議變更會在工作執行時變更專案狀態,且不會引入過時資料時,Dataplex Universal Catalog 就會更新專案中的值。建議的變更必須參照中繼資料匯入檔案中的更新遮罩欄位或 aspect keys 欄位。

比較邏輯會因您執行的中繼資料匯入工作類型而異。

完整項目同步處理工作

在完整項目同步中繼資料作業中,Dataplex Universal Catalog 會針對作業範圍內的每個項目執行下列其中一項操作:

  • 建立項目和附加切面。如果中繼資料匯入檔案包含專案中不存在的項目,Dataplex Universal Catalog 會建立該項目並附加切面。
  • 刪除項目和附加的切面。如果專案中存在項目,但中繼資料匯入檔案未包含該項目,Dataplex Universal Catalog 會從專案中刪除該項目及其附加的層面。
  • 更新項目和附加的切面。如果項目同時存在於中繼資料匯入檔案和專案中,Dataplex Universal Catalog 會評估與項目相關聯的項目來源時間戳記和層面來源時間戳記,判斷要修改哪些值。接著,Dataplex Universal Catalog 會執行下列一或多項操作:

    • 重新建立項目。如果中繼資料匯入檔案中的項目來源建立時間戳記,比專案中的對應時間戳記更新,Dataplex Universal Catalog 會在專案中重新建立項目。
    • 更新項目。如果中繼資料匯入檔案中的項目來源更新時間戳記,比專案中的對應時間戳記更新,Dataplex Universal Catalog 就會更新專案中的項目。
    • 建立切面。如果專案中沒有某個切面,但中繼資料匯入檔案的切面對應、更新遮罩欄位和切面鍵欄位中包含該切面,Dataplex Universal Catalog 就會建立該切面。
    • 刪除切面。如果專案中存在某個層面,且該層面包含在更新遮罩欄位和中繼資料匯入檔案的層面鍵欄位中,但未包含在層面對應中,Dataplex Universal Catalog 會刪除該層面。
    • 更新切面。如果專案中存在切面,且切面包含在切面對應、更新遮罩欄位和中繼資料匯入檔案中的切面鍵欄位,且中繼資料匯入檔案中的切面來源更新時間戳記比專案中的對應時間戳記新,Dataplex Universal Catalog 就會更新切面。

      如果中繼資料匯入檔案中未提供切面來源更新時間戳記,但相應項目已標示為要更新,Dataplex Universal Catalog 也會更新切面。

      不過,如果中繼資料匯入檔案中至少有一個切面的時間戳記比專案中的對應時間戳記舊,Dataplex Universal Catalog 就不會更新附加的項目。

僅限外觀的工作

在僅限切面的中繼資料工作中,Dataplex Universal Catalog 會針對工作中範圍內的每個切面,執行下列其中一項操作:

  • 建立切面。如果專案中沒有某個切面,但中繼資料匯入檔案的更新遮罩欄位和切面鍵欄位中包含該切面,Dataplex Universal Catalog 就會建立該切面。
  • 刪除切面。如果是選用層面,如果層面存在於專案中,且包含在更新遮罩欄位和中繼資料匯入檔案的層面鍵欄位中,但未包含在層面對應中,Dataplex Universal Catalog 會刪除該層面。

    無法刪除必要切面。

  • 更新切面。如果專案中存在切面,且切面包含在切面對應、更新遮罩欄位和中繼資料匯入檔案中的切面鍵欄位,且中繼資料匯入檔案中的切面來源更新時間戳記比專案中的對應時間戳記新,Dataplex Universal Catalog 就會更新切面。

    如果中繼資料匯入檔案中未提供切面來源更新時間戳記,Dataplex Universal Catalog 也會更新切面。

    Dataplex Universal Catalog 會根據切面來源更新時間戳記更新切面,無論對應項目的項目來源更新時間戳記為何。

建立中繼資料匯入檔案

匯入中繼資料前,請先為工作建立中繼資料匯入檔案。請按照下列步驟操作:

  1. 按照本文件先前的說明,準備中繼資料匯入檔案
  2. 將檔案上傳至 Cloud Storage bucket

您可以在同一個中繼資料工作中提供多個中繼資料匯入檔案。如要提供多個檔案,請將檔案儲存在同一個 Cloud Storage 值區。執行工作時,您會指定 bucket,而非特定檔案。Dataplex Universal Catalog 會從儲存在 bucket 中的所有檔案匯入中繼資料,包括子資料夾中的檔案。

執行中繼資料匯入工作

建立中繼資料匯入檔案後,請執行中繼資料匯入工作。

C#

C#

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

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

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

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

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

Go

Go

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

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


package main

import (
	"context"

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

func main() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := dataplex.NewCatalogClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

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

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

Java

Java

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

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

import com.google.cloud.dataplex.v1.CatalogServiceClient;
import com.google.cloud.dataplex.v1.CreateMetadataJobRequest;
import com.google.cloud.dataplex.v1.LocationName;
import com.google.cloud.dataplex.v1.MetadataJob;

public class SyncCreateMetadataJob {

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

  public static void syncCreateMetadataJob() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
      CreateMetadataJobRequest request =
          CreateMetadataJobRequest.newBuilder()
              .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
              .setMetadataJob(MetadataJob.newBuilder().build())
              .setMetadataJobId("metadataJobId-2021530679")
              .setValidateOnly(true)
              .build();
      MetadataJob response = catalogServiceClient.createMetadataJobAsync(request).get();
    }
  }
}

Python

Python

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

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

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


def sample_create_metadata_job():
    # Create a client
    client = dataplex_v1.CatalogServiceClient()

    # Initialize request argument(s)
    metadata_job = dataplex_v1.MetadataJob()
    metadata_job.import_spec.scope.entry_groups = [
        "entry_groups_value1",
        "entry_groups_value2",
    ]
    metadata_job.import_spec.scope.entry_types = [
        "entry_types_value1",
        "entry_types_value2",
    ]
    metadata_job.import_spec.entry_sync_mode = "NONE"
    metadata_job.import_spec.aspect_sync_mode = "NONE"
    metadata_job.type_ = "EXPORT"

    request = dataplex_v1.CreateMetadataJobRequest(
        parent="parent_value",
        metadata_job=metadata_job,
    )

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

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

    response = operation.result()

    # Handle the response
    print(response)

Ruby

Ruby

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

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

require "google/cloud/dataplex/v1"

##
# Snippet for the create_metadata_job call in the CatalogService service
#
# This snippet has been automatically generated and should be regarded as a code
# template only. It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in https://cloud.google.com/ruby/docs/reference.
#
# This is an auto-generated example demonstrating basic usage of
# Google::Cloud::Dataplex::V1::CatalogService::Client#create_metadata_job.
#
def create_metadata_job
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::Dataplex::V1::CatalogService::Client.new

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

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

  # The returned object is of type Gapic::Operation. You can use it to
  # check the status of an operation, cancel it, or wait for results.
  # Here is how to wait for a response.
  result.wait_until_done! timeout: 60
  if result.response?
    p result.response
  else
    puts "No response received."
  end
end

REST

如要匯入中繼資料,請使用 metadataJobs.create 方法

使用任何要求資料之前,請先替換以下項目:

  • PROJECT_NUMBER:您的 Google Cloud 專案編號或專案 ID。
  • LOCATION_ID: Google Cloud 位置,例如 us-central1
  • METADATA_JOB_ID:選用。中繼資料工作 ID。
  • CLOUD_STORAGE_URI:Cloud Storage 值區或資料夾的 URI,其中包含中繼資料匯入檔案。如要進一步瞭解檔案規定,請參閱中繼資料匯入檔案

  • ENTRY_GROUP:作業範圍內項目群組的相對資源名稱,格式為 projects/PROJECT_ID_OR_NUMBER/locations/LOCATION_ID/entryGroups/ENTRY_GROUP_ID。詳情請參閱「工作範圍」。
  • ENTRY_TYPE:工作範圍內項目類型的相對資源名稱,格式為 projects/PROJECT_ID_OR_NUMBER/locations/LOCATION_ID/entryTypes/ENTRY_TYPE_ID。詳情請參閱「工作範圍」。

  • ASPECT_TYPE:工作範圍內某個面向類型的相對資源名稱,格式為 projects/PROJECT_ID_OR_NUMBER/locations/LOCATION_ID/aspectTypes/ASPECT_TYPE_ID。建立完整項目同步處理工作時為選填,建立僅限層面工作時為必填。 詳情請參閱「工作範圍」。
  • ENTRY_SYNC_MODE:項目同步模式,例如 FULLNONE。詳情請參閱同步模式
  • LOG_LEVEL:要擷取的記錄層級,例如 INFODEBUG。詳情請參閱「查看工作記錄及排解問題」。

HTTP 方法和網址:

POST https://dataplex.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/metadataJobs?metadataJobId=METADATA_JOB_ID

JSON 要求主體:

{
  "type": "IMPORT",
  "import_spec": {
    "source_storage_uri": "gs://CLOUD_STORAGE_URI/",
    "scope": {
      "entryGroups": [
        "ENTRY_GROUP"
      ],
      "entry_types": [
        "ENTRY_TYPE"
      ],
      "aspect_types": [
        "ASPECT_TYPE"
      ]
    },
    "entry_sync_mode": "ENTRY_SYNC_MODE",
    "aspect_sync_mode": "INCREMENTAL",
    "log_level": "LOG_LEVEL"
  }
}

請展開以下其中一個選項,以傳送要求:

回應會識別長時間執行的作業。

取得中繼資料工作的詳細資料

如要取得中繼資料工作資訊,例如工作狀態和修改的項目數量,請按照下列步驟操作。 如要進一步瞭解如何排解工作失敗問題,請參閱本文的「查看工作記錄並排解問題」一節。

C#

C#

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

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

using Google.Cloud.Dataplex.V1;

public sealed partial class GeneratedCatalogServiceClientSnippets
{
    /// <summary>Snippet for GetMetadataJob</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 GetMetadataJobRequestObject()
    {
        // Create client
        CatalogServiceClient catalogServiceClient = CatalogServiceClient.Create();
        // Initialize request argument(s)
        GetMetadataJobRequest request = new GetMetadataJobRequest
        {
            MetadataJobName = MetadataJobName.FromProjectLocationMetadataJob("[PROJECT]", "[LOCATION]", "[METADATAJOB]"),
        };
        // Make the request
        MetadataJob response = catalogServiceClient.GetMetadataJob(request);
    }
}

Go

Go

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

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


package main

import (
	"context"

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

func main() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := dataplex.NewCatalogClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

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

Java

Java

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

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

import com.google.cloud.dataplex.v1.CatalogServiceClient;
import com.google.cloud.dataplex.v1.GetMetadataJobRequest;
import com.google.cloud.dataplex.v1.MetadataJob;
import com.google.cloud.dataplex.v1.MetadataJobName;

public class SyncGetMetadataJob {

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

  public static void syncGetMetadataJob() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
      GetMetadataJobRequest request =
          GetMetadataJobRequest.newBuilder()
              .setName(MetadataJobName.of("[PROJECT]", "[LOCATION]", "[METADATAJOB]").toString())
              .build();
      MetadataJob response = catalogServiceClient.getMetadataJob(request);
    }
  }
}

Python

Python

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

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

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


def sample_get_metadata_job():
    # Create a client
    client = dataplex_v1.CatalogServiceClient()

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

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

    # Handle the response
    print(response)

Ruby

Ruby

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

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

require "google/cloud/dataplex/v1"

##
# Snippet for the get_metadata_job call in the CatalogService service
#
# This snippet has been automatically generated and should be regarded as a code
# template only. It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in https://cloud.google.com/ruby/docs/reference.
#
# This is an auto-generated example demonstrating basic usage of
# Google::Cloud::Dataplex::V1::CatalogService::Client#get_metadata_job.
#
def get_metadata_job
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::Dataplex::V1::CatalogService::Client.new

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

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

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

REST

如要取得中繼資料工作相關資訊,請使用 metadataJobs.get 方法

取得中繼資料工作清單

您可以取得最近的中繼資料工作清單。系統會定期刪除已達到終止狀態的舊工作。

C#

C#

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

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

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

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

        // Iterate over all response items, lazily performing RPCs as required
        foreach (MetadataJob item in response)
        {
            // Do something with each item
            Console.WriteLine(item);
        }

        // Or iterate over pages (of server-defined size), performing one RPC per page
        foreach (ListMetadataJobsResponse page in response.AsRawResponses())
        {
            // Do something with each page of items
            Console.WriteLine("A page of results:");
            foreach (MetadataJob item in page)
            {
                // Do something with each item
                Console.WriteLine(item);
            }
        }

        // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
        int pageSize = 10;
        Page<MetadataJob> singlePage = response.ReadPage(pageSize);
        // Do something with the page of items
        Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
        foreach (MetadataJob item in singlePage)
        {
            // Do something with each item
            Console.WriteLine(item);
        }
        // Store the pageToken, for when the next page is required.
        string nextPageToken = singlePage.NextPageToken;
    }
}

Go

Go

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

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


package main

import (
	"context"

	dataplex "cloud.google.com/go/dataplex/apiv1"
	dataplexpb "cloud.google.com/go/dataplex/apiv1/dataplexpb"
	"google.golang.org/api/iterator"
)

func main() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := dataplex.NewCatalogClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &dataplexpb.ListMetadataJobsRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/dataplex/apiv1/dataplexpb#ListMetadataJobsRequest.
	}
	it := c.ListMetadataJobs(ctx, req)
	for {
		resp, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			// TODO: Handle error.
		}
		// TODO: Use resp.
		_ = resp

		// If you need to access the underlying RPC response,
		// you can do so by casting the `Response` as below.
		// Otherwise, remove this line. Only populated after
		// first call to Next(). Not safe for concurrent access.
		_ = it.Response.(*dataplexpb.ListMetadataJobsResponse)
	}
}

Java

Java

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

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

import com.google.cloud.dataplex.v1.CatalogServiceClient;
import com.google.cloud.dataplex.v1.ListMetadataJobsRequest;
import com.google.cloud.dataplex.v1.LocationName;
import com.google.cloud.dataplex.v1.MetadataJob;

public class SyncListMetadataJobs {

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

  public static void syncListMetadataJobs() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
      ListMetadataJobsRequest request =
          ListMetadataJobsRequest.newBuilder()
              .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
              .setPageSize(883849137)
              .setPageToken("pageToken873572522")
              .setFilter("filter-1274492040")
              .setOrderBy("orderBy-1207110587")
              .build();
      for (MetadataJob element : catalogServiceClient.listMetadataJobs(request).iterateAll()) {
        // doThingsWith(element);
      }
    }
  }
}

Python

Python

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

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

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


def sample_list_metadata_jobs():
    # Create a client
    client = dataplex_v1.CatalogServiceClient()

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

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

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

Ruby

Ruby

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

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

require "google/cloud/dataplex/v1"

##
# Snippet for the list_metadata_jobs call in the CatalogService service
#
# This snippet has been automatically generated and should be regarded as a code
# template only. It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in https://cloud.google.com/ruby/docs/reference.
#
# This is an auto-generated example demonstrating basic usage of
# Google::Cloud::Dataplex::V1::CatalogService::Client#list_metadata_jobs.
#
def list_metadata_jobs
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::Dataplex::V1::CatalogService::Client.new

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

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

  # The returned object is of type Gapic::PagedEnumerable. You can iterate
  # over elements, and API calls will be issued to fetch pages as needed.
  result.each do |item|
    # Each element is of type ::Google::Cloud::Dataplex::V1::MetadataJob.
    p item
  end
end

REST

如要取得最近的中繼資料工作清單,請使用 metadataJobs.list 方法

取消中繼資料工作

如果不想執行中繼資料工作,可以取消。

C#

C#

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

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

using Google.Cloud.Dataplex.V1;

public sealed partial class GeneratedCatalogServiceClientSnippets
{
    /// <summary>Snippet for CancelMetadataJob</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 CancelMetadataJobRequestObject()
    {
        // Create client
        CatalogServiceClient catalogServiceClient = CatalogServiceClient.Create();
        // Initialize request argument(s)
        CancelMetadataJobRequest request = new CancelMetadataJobRequest
        {
            MetadataJobName = MetadataJobName.FromProjectLocationMetadataJob("[PROJECT]", "[LOCATION]", "[METADATAJOB]"),
        };
        // Make the request
        catalogServiceClient.CancelMetadataJob(request);
    }
}

Go

Go

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

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


package main

import (
	"context"

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

func main() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := dataplex.NewCatalogClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

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

Java

Java

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

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

import com.google.cloud.dataplex.v1.CancelMetadataJobRequest;
import com.google.cloud.dataplex.v1.CatalogServiceClient;
import com.google.cloud.dataplex.v1.MetadataJobName;
import com.google.protobuf.Empty;

public class SyncCancelMetadataJob {

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

  public static void syncCancelMetadataJob() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
      CancelMetadataJobRequest request =
          CancelMetadataJobRequest.newBuilder()
              .setName(MetadataJobName.of("[PROJECT]", "[LOCATION]", "[METADATAJOB]").toString())
              .build();
      catalogServiceClient.cancelMetadataJob(request);
    }
  }
}

Python

Python

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

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

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


def sample_cancel_metadata_job():
    # Create a client
    client = dataplex_v1.CatalogServiceClient()

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

    # Make the request
    client.cancel_metadata_job(request=request)

Ruby

Ruby

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

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

require "google/cloud/dataplex/v1"

##
# Snippet for the cancel_metadata_job call in the CatalogService service
#
# This snippet has been automatically generated and should be regarded as a code
# template only. It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in https://cloud.google.com/ruby/docs/reference.
#
# This is an auto-generated example demonstrating basic usage of
# Google::Cloud::Dataplex::V1::CatalogService::Client#cancel_metadata_job.
#
def cancel_metadata_job
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::Dataplex::V1::CatalogService::Client.new

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

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

  # The returned object is of type Google::Protobuf::Empty.
  p result
end

REST

如要取消中繼資料工作,請使用 metadataJobs.cancel 方法

查看工作記錄檔並排解問題

使用 Cloud Logging 查看中繼資料工作的記錄。詳情請參閱「監控 Dataplex Universal Catalog 記錄」。

建立中繼資料工作時,您可以設定記錄層級。可用的記錄層級如下:

  • INFO:提供整體工作層級的記錄。包含匯入項目的匯總記錄,但不指定哪個匯入項目發生錯誤。
  • DEBUG:提供每個匯入項目的詳細記錄。使用偵錯層級記錄,排解特定匯入項目問題。舉例來說,您可以使用偵錯層級的記錄,找出工作範圍中缺少的資源、不符合相關聯項目類型或層面類型的項目或層面,或是中繼資料匯入檔案的其他設定錯誤。

驗證錯誤

Dataplex Universal Catalog 會根據專案中的現有中繼資料,驗證中繼資料匯入檔案。如果發生驗證問題,工作狀態可能會傳回下列其中一種狀態:

  • FAILED:中繼資料匯入檔案發生錯誤。Dataplex Universal Catalog 不會匯入任何中繼資料,且工作會失敗。中繼資料匯入檔案中的錯誤範例如下:
    • 檔案中的項目無法剖析為有效的匯入項目
    • 檔案中的項目或層面屬於項目群組、項目類型或層面類型,但不在工作範圍內
    • 工作中的項目名稱重複指定
    • 在方面對應或方面鍵中指定的方面類型未使用 PROJECT_ID_OR_NUMBER.LOCATION_ID.ASPECT_TYPE_ID@OPTIONAL_PATH 格式
    • 必要層面標示為待刪除
  • SUCCEEDED_WITH_ERRORS:中繼資料匯入檔案可以順利剖析,但匯入檔案中的項目會導致專案中的項目處於不一致的狀態。Dataplex Universal Catalog 會忽略這類項目,但會匯入檔案中的其餘中繼資料。

使用工作記錄檔排解錯誤。

後續步驟