データ品質の問題をスキャンする

このドキュメントでは、BigQuery と Dataplex Universal Catalog を組み合わせて使用し、データが品質要件を満たしていることを確認する方法について説明します。Dataplex Universal Catalog の自動データ品質を使用すると、BigQuery テーブル内のデータの品質を定義して測定できます。データのスキャンを自動化して、定義済みルールに照らしてデータを検証し、データが品質要件を満たしていない場合はアラートを記録できます。

自動データ品質の詳細については、自動データ品質の概要をご覧ください。

始める前に

  1. Enable the Dataplex API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  2. 省略可: データ プロファイル スキャンの結果に基づいてデータ品質ルールの推奨事項を Dataplex Universal Catalog で生成する場合は、データ プロファイル スキャンを作成して実行します。

必要なロール

このセクションでは、Dataplex Universal Catalog のデータ品質スキャンを使用するために必要な IAM のロールと権限について説明します。

ユーザーの役割と権限

データ品質スキャンの実行と管理に必要な権限を取得するには、次の IAM ロールを付与するよう管理者に依頼してください。

  • BigQuery テーブルでデータ品質スキャンを実行します。
  • データ品質スキャン結果を Dataplex Universal Catalog に公開する:
  • DataScan リソースで特定のタスクを実行します。

ロールの付与については、プロジェクト、フォルダ、組織へのアクセス権の管理をご覧ください。

これらの事前定義ロールには、データ品質スキャンの実行と管理に必要な権限が含まれています。必要とされる正確な権限については、「必要な権限」セクションを開いてご確認ください。

必要な権限

データ品質スキャンを実行して管理するには、次の権限が必要です。

  • BigQuery テーブルでデータ品質スキャンを実行します。
    • スキャンジョブを実行するには、プロジェクトに対する bigquery.jobs.create
    • スキャンする BigQuery テーブルに対する bigquery.tables.get
    • スキャンする BigQuery テーブルに対する bigquery.tables.getData
  • データ品質スキャン結果を Dataplex Universal Catalog に公開する:
    • スキャンされたテーブルに対する bigquery.tables.update
    • テーブルと同じロケーションにある @bigquery エントリ グループに対する dataplex.entryGroups.useDataQualityScorecardAspect
  • DataScan を作成する: プロジェクトに対する dataplex.datascans.create
  • DataScan を削除する: プロジェクトに対する dataplex.datascans.delete
  • DataScan メタデータを表示する: プロジェクトに対する dataplex.datascans.get
  • ルールと結果を含む DataScan の詳細を表示する: プロジェクトに対する dataplex.datascans.getData
  • DataScan を一覧表示する: プロジェクトに対する dataplex.datascans.list
  • プロジェクトに対する dataplex.datascans.run 権限: DataScan を実行する
  • DataScan を更新する: プロジェクトに対する dataplex.datascans.update
  • DataScan の IAM ポリシーを取得または設定する:
    • プロジェクトに対する dataplex.datascans.getIamPolicy
    • プロジェクトに対する dataplex.datascans.setIamPolicy

カスタムロールや他の事前定義ロールを使用して、これらの権限を取得することもできます。

BigQuery の列レベルのアクセス ポリシーで保護されている列にアクセスする必要がある場合は、それらの列に対する権限も必要です。

Dataplex Universal Catalog サービス アカウントのロールと権限

データ品質スキャンやデータ プロファイル スキャンをまだ作成していない場合、またはこのプロジェクトに Dataplex Universal Catalog レイクがない場合は、gcloud beta services identity create --service=dataplex.googleapis.com を実行してサービス ID を作成してください。このコマンドは、Dataplex Universal Catalog サービス ID が存在する場合に該当する ID を返します。

データ品質スキャンを含むプロジェクトの Dataplex Universal Catalog サービス アカウントに、さまざまなソースからデータを読み取って結果をエクスポートするために必要な権限が付与されるように、データ品質スキャンを含むプロジェクトの Dataplex Universal Catalog サービス アカウントに次の IAM ロールを付与するよう管理者に依頼してください。

  • BigQuery テーブルのデータを読み取る: スキャンする BigQuery テーブルと、ルールで参照される他のテーブルに対する BigQuery データ閲覧者 roles/bigquery.dataViewer
  • スキャン結果を BigQuery テーブルにエクスポートする: 結果のデータセットとテーブルに対する BigQuery データ編集者 roles/bigquery.dataEditor
  • Dataplex Universal Catalog レイクに編成された BigQuery データをスキャンする:
  • Cloud Storage から BigQuery 外部テーブルをスキャンする: Cloud Storage バケットに対する Storage オブジェクト閲覧者 roles/storage.objectViewer

ロールの付与については、プロジェクト、フォルダ、組織へのアクセス権の管理をご覧ください。

これらの事前定義ロールには、さまざまなソースからデータを読み取って結果をエクスポートするために必要な権限が含まれています。必要とされる正確な権限については、「必要な権限」セクションを開いてご確認ください。

必要な権限

さまざまなソースからデータを読み取り、結果をエクスポートするには、次の権限が必要です。

  • BigQuery テーブルデータを読み取る:
    • BigQuery テーブルに対する bigquery.tables.get
    • BigQuery テーブルに対する bigquery.tables.getData
  • スキャン結果を BigQuery テーブルにエクスポートします。
    • 結果データセットとテーブルに対する bigquery.datasets.get
    • 結果データセットとテーブルに対する bigquery.tables.create
    • 結果データセットとテーブルに対する bigquery.tables.get
    • 結果データセットとテーブルに対する bigquery.tables.getData
    • 結果データセットとテーブルに対する bigquery.tables.update
    • 結果データセットとテーブルに対する bigquery.tables.updateData
  • Dataplex Universal Catalog レイクに編成された BigQuery データをスキャンする:
    • Dataplex リソースに対する dataplex.lakes.list
    • Dataplex リソースに対する dataplex.lakes.get
    • Dataplex リソースに対する dataplex.zones.list
    • Dataplex リソースに対する dataplex.zones.get
    • Dataplex リソースに対する dataplex.entities.list
    • Dataplex リソースに対する dataplex.entities.get
    • Dataplex リソースに対する dataplex.operations.get
  • Cloud Storage から BigQuery 外部テーブルをスキャンします。
    • Cloud Storage バケットに対する storage.buckets.get
    • Cloud Storage バケットに対する storage.objects.get

管理者は、データ品質スキャンを含むプロジェクトの Dataplex ユニバーサル カタログ サービス アカウントに、カスタムロールや他の事前定義ロールを付与することもできます。

BigQuery の列レベルのアクセス ポリシーで保護されている列にアクセスする必要がある場合は、それらの列に対する権限を Dataplex Universal Catalog サービス アカウントに割り当てます。

テーブルで BigQuery 行レベルのアクセス ポリシーが有効になっている場合、Dataplex Universal Catalog サービス アカウントに表示される行のみをスキャンできます。行レベルのポリシーに対する個々のユーザーのアクセス権限は評価されません。

データ品質スキャンを作成する

コンソール

  1. Google Cloud コンソールの BigQuery の [メタデータのキュレーション] ページで、[データのプロファイリングと品質] タブに移動します。

    [データのプロファイリングと品質] に移動

  2. [データ品質スキャンの作成] をクリックします。

  3. [スキャンの定義] ウィンドウで、次のフィールドに入力します。

    1. 省略可: 表示名を入力します。

    2. ID を入力します。リソースの命名規則をご覧ください。

    3. (省略可)説明を入力します。

    4. [テーブル] フィールドで、[参照] をクリックします。スキャンするテーブルを選択し、[選択] をクリックします。標準の BigQuery テーブルのみがサポートされています。

      マルチリージョン データセット内のテーブルの場合は、データスキャンを作成するリージョンを選択します。

      Dataplex Universal Catalog レイク内で整理されたテーブルを参照するには、[Dataplex レイク内のブラウジング] をクリックします。

    5. [スコープ] フィールドで、[増分] または [データ全体] を選択します。

      • [増分] を選択した場合、[タイムスタンプ列] フィールドで、新しいレコードが追加されるたびに増加し、新しいレコードの識別に使用できる BigQuery テーブルから、DATE 型または TIMESTAMP 型の列を選択します。テーブルを分割する列でもかまいません。
    6. データをフィルタするには、[行のフィルタリング] チェックボックスをオンにします。GoogleSQL 構文の WHEREの一部として使用できる有効な SQL 式で構成される行フィルタを指定します。例: col1 >= 0フィルタには、複数の列条件を組み合わせることができます。例: col1 >= 0 AND col2 < 10

    7. データをサンプリングするには、[サンプリング サイズ] リストでサンプリング率を選択します。0.0~100.0% の範囲のパーセンテージ値(小数点以下 3 桁まで)を選択します。大規模なデータセットの場合は、低いサンプリング率を選択します。たとえば、1 PB のテーブルの場合、0.1%~1.0% の値を入力すると、データ品質スキャンは 1~10 TB のデータをサンプリングします。増分データスキャンの場合、データ品質スキャンは最新の増分にサンプリングを適用します。

    8. データ品質スキャンの結果を Dataplex Universal Catalog メタデータとして公開するには、[結果を Dataplex Catalog に公開する] チェックボックスをオンにします。

      最新のスキャン結果は、ソーステーブルの BigQuery ページと Dataplex Universal Catalog ページの [データ品質] タブで表示できます。ユーザーが公開されたスキャン結果にアクセスできるようにするには、このドキュメントのデータ品質スキャンの結果へのアクセスを許可するをご覧ください。

    9. [スケジュール] セクションで、次のいずれかのオプションを選択します。

      • 繰り返し: データ品質スキャンを 1 時間ごと、毎日、毎週、毎月、カスタムのいずれかのスケジュールで実行します。スキャンの実行頻度と時間を指定します。[カスタム] を選択した場合は、cron 形式を使用してスケジュールを指定します。

      • オンデマンド: データ品質スキャンをオンデマンドで実行します。

      • 1 回限りの実行: データ品質スキャンを今すぐ 1 回実行し、有効期間後にスキャンを削除します。この機能はプレビュー版です。

      • 有効期間: 有効期間の値は、スキャンが実行されてから削除されるまでの期間です。有効期間が指定されていないデータ品質スキャンは、実行後 24 時間で自動的に削除されます。有効期間は 0 秒(即時削除)から 365 日の範囲で設定できます。

    10. [続行] をクリックします。

  4. [データ品質ルール] ウィンドウで、このデータ品質スキャン用に構成するルールを定義します。

    1. [ルールを追加] をクリックし、次のいずれかのオプションを選択します。

      • プロフィールに基づく推奨事項: 既存のデータ プロファイリング スキャンに基づいて、推奨事項からルールを作成します。

        1. 列の選択: 推奨ルールを取得する列を選択します。

        2. スキャン プロジェクトの選択: データ プロファイリング スキャンがデータ品質スキャンを作成するプロジェクトとは異なるプロジェクトにある場合は、プロファイル スキャンを取得するプロジェクトを選択します。

        3. プロファイルの結果を選択: 1 つ以上のプロファイルの結果を選択し、[OK] をクリックします。これにより、出発点として使用できる推奨ルールのリストが入力されます。

        4. 追加するルールのチェックボックスをオンにして、[選択] をクリックします。選択したルールは、現在のルールリストに追加されます。その後、ルールを編集できます。

      • 組み込みルールの種類: 事前定義ルールからルールを作成します。事前定義ルールのリストを確認します。

        1. 列の選択: ルールを選択する列を選択します。

        2. ルールの種類を選択: 選択するルールの種類を選択し、[OK] をクリックします。表示されるルールの種類は、選択した列によって異なります。

        3. 追加するルールのチェックボックスをオンにして、[選択] をクリックします。選択したルールは、現在のルールリストに追加されます。その後、ルールを編集できます。

      • SQL 行チェックルール: 各行に適用するカスタム SQL ルールを作成します。

        1. [ディメンション] で、ディメンションを 1 つ選択します。

        2. [合格のしきい値] で、チェックに合格する必要があるレコードの割合を選択します。

        3. [列名] で列を選択します。

        4. [SQL 式を指定] フィールドに、ブール値の true(合格)または false(不合格)と評価される SQL 式を入力します。詳細については、サポートされているカスタム SQL ルールの種類と、データ品質ルールを定義するの例をご覧ください。

        5. [追加] をクリックします。

      • SQL 集計チェックルール: カスタム SQL テーブル条件ルールを作成します。

        1. [ディメンション] で、ディメンションを 1 つ選択します。

        2. [列名] で列を選択します。

        3. [SQL 式を指定] フィールドに、ブール値の true(合格)または false(不合格)と評価される SQL 式を入力します。詳細については、サポートされているカスタム SQL ルールの種類と、データ品質ルールを定義するの例をご覧ください。

        4. [追加] をクリックします。

      • SQL アサーション ルール: データの無効な状態を確認するカスタム SQL アサーション ルールを作成します。

        1. [ディメンション] で、ディメンションを 1 つ選択します。

        2. 省略可: [列名] で列を選択します。

        3. [SQL ステートメントを指定] フィールドに、無効な状態と一致する行を返す SQL ステートメントを入力します。行が返された場合、このルールは失敗します。SQL ステートメントの末尾のセミコロンを省略します。詳細については、サポートされているカスタム SQL ルールの種類と、データ品質ルールを定義するの例をご覧ください。

        4. [追加] をクリックします。

    2. 省略可: どのデータ品質ルールでも、モニタリングとアラートに使用するカスタムルール名と説明を割り当てることができます。これを行うには、ルールを編集して、次の詳細を指定します。

      • ルール名: カスタムルール名を 63 文字以下で入力します。ルール名には、文字(az、AZ)、数字(0~9)、ハイフン(-)を使用できます。先頭は文字、末尾は数字または文字にする必要があります
      • 説明: ルールの説明を入力します。最大長は 1,024 文字です。
    3. 前の手順を繰り返して、データ品質スキャンにルールを追加します。完了したら、[次へ] をクリックします。

  5. 省略可: スキャン結果を BigQuery 標準テーブルにエクスポートします。[スキャン結果を BigQuery テーブルにエクスポートする] セクションで、次の操作を行います。

    1. [BigQuery データセットの選択] フィールドで、[参照] をクリックします。 データ品質のスキャン結果を保存する BigQuery データセットを選択します。

    2. [BigQuery テーブル] フィールドで、データ品質スキャンの結果を保存するテーブルを指定します。既存のテーブルを使用している場合は、エクスポート テーブル スキーマと互換性があることを確認してください。指定したテーブルが存在しない場合は、Dataplex Universal Catalog によって作成されます。

  6. 省略可: ラベルを追加します。ラベルは、関連するオブジェクトをまとめてグループ化したり、他の Google Cloud リソースと組み合わせてグループ化できる Key-Value ペアです。

  7. 省略可: データ品質スキャンジョブのステータスと結果に関するアラートを送信するメール通知レポートを設定します。[通知レポート] セクションで [メール ID を追加] をクリックし、最大 5 つのメールアドレスを入力します。次に、レポートの送信先のシナリオを選択します。

    • 品質スコア(<=): ジョブが成功し、データ品質スコアが指定された目標スコアより低い場合にレポートを送信します。0~100 のターゲット品質スコアを入力します。
    • ジョブの失敗: データ品質の結果に関係なく、ジョブ自体が失敗するとレポートが送信されます。
    • ジョブの完了(成功または失敗): データ品質の結果に関係なく、ジョブが終了するとレポートが送信されます。
  8. [作成] をクリックします。

    スキャンが作成されたら、[今すぐ実行] をクリックすることで、いつでもスキャンを実行できます。

gcloud

データ品質スキャンを作成するには、gcloud dataplex datascans create data-quality コマンドを使用します。

ソースデータが Dataplex Universal Catalog レイクに編成されている場合は、--data-source-entity フラグを指定します。

gcloud dataplex datascans create data-quality DATASCAN \
    --location=LOCATION \
    --data-quality-spec-file=DATA_QUALITY_SPEC_FILE \
    --data-source-entity=DATA_SOURCE_ENTITY

ソースデータが Dataplex Universal Catalog レイクに編成されていない場合は、--data-source-resource フラグを指定します。

gcloud dataplex datascans create data-quality DATASCAN \
    --location=LOCATION \
    --data-quality-spec-file=DATA_QUALITY_SPEC_FILE \
    --data-source-resource=DATA_SOURCE_RESOURCE

次の変数を置き換えます。

  • DATASCAN: データ品質スキャンの名前。
  • LOCATION: データ品質スキャンを作成する Google Cloud リージョン。
  • DATA_QUALITY_SPEC_FILE: データ品質スキャンの仕様を含む JSON または YAML ファイルのパス。このファイルは、ローカル ファイルまたは接頭辞 gs:// を持つ Cloud Storage パスです。このファイルを使用して、スキャンのデータ品質ルールを指定します。このファイルで、フィルタ、サンプリング率、BigQuery へのエクスポートやメール通知レポートの送信などのスキャン後のアクションなどのその他の詳細を指定することもできます。JSON 表現のドキュメントYAML 表現の例をご覧ください。
  • DATA_SOURCE_ENTITY: データ品質スキャンのデータを含む Dataplex Universal Catalog エンティティ。例: projects/test-project/locations/test-location/lakes/test-lake/zones/test-zone/entities/test-entity
  • DATA_SOURCE_RESOURCE: データ品質スキャンのデータを含むリソースの名前。例: //bigquery.googleapis.com/projects/test-project/datasets/test-dataset/tables/test-table

C#

C#

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

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

public sealed partial class GeneratedDataScanServiceClientSnippets
{
    /// <summary>Snippet for CreateDataScan</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 CreateDataScanRequestObject()
    {
        // Create client
        DataScanServiceClient dataScanServiceClient = DataScanServiceClient.Create();
        // Initialize request argument(s)
        CreateDataScanRequest request = new CreateDataScanRequest
        {
            ParentAsLocationName = LocationName.FromProjectLocation("[PROJECT]", "[LOCATION]"),
            DataScan = new DataScan(),
            DataScanId = "",
            ValidateOnly = false,
        };
        // Make the request
        Operation<DataScan, OperationMetadata> response = dataScanServiceClient.CreateDataScan(request);

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

Go

Go

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


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.NewDataScanClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &dataplexpb.CreateDataScanRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/dataplex/apiv1/dataplexpb#CreateDataScanRequest.
	}
	op, err := c.CreateDataScan(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

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

import com.google.cloud.dataplex.v1.CreateDataScanRequest;
import com.google.cloud.dataplex.v1.DataScan;
import com.google.cloud.dataplex.v1.DataScanServiceClient;
import com.google.cloud.dataplex.v1.LocationName;

public class SyncCreateDataScan {

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

  public static void syncCreateDataScan() 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 (DataScanServiceClient dataScanServiceClient = DataScanServiceClient.create()) {
      CreateDataScanRequest request =
          CreateDataScanRequest.newBuilder()
              .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
              .setDataScan(DataScan.newBuilder().build())
              .setDataScanId("dataScanId1260787906")
              .setValidateOnly(true)
              .build();
      DataScan response = dataScanServiceClient.createDataScanAsync(request).get();
    }
  }
}

Node.js

Node.js

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ** This file is automatically generated by gapic-generator-typescript. **
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **



'use strict';

function main(parent, dataScan, dataScanId) {
  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The resource name of the parent location:
   *  `projects/{project}/locations/{location_id}`
   *  where `project` refers to a *project_id* or *project_number* and
   *  `location_id` refers to a Google Cloud region.
   */
  // const parent = 'abc123'
  /**
   *  Required. DataScan resource.
   */
  // const dataScan = {}
  /**
   *  Required. DataScan identifier.
   *  * Must contain only lowercase letters, numbers and hyphens.
   *  * Must start with a letter.
   *  * Must end with a number or a letter.
   *  * Must be between 1-63 characters.
   *  * Must be unique within the customer project / location.
   */
  // const dataScanId = 'abc123'
  /**
   *  Optional. Only validate the request, but do not perform mutations.
   *  The default is `false`.
   */
  // const validateOnly = true

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

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

  async function callCreateDataScan() {
    // Construct request
    const request = {
      parent,
      dataScan,
      dataScanId,
    };

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

  callCreateDataScan();
}

process.on('unhandledRejection', err => {
  console.error(err.message);
  process.exitCode = 1;
});
main(...process.argv.slice(2));

Python

Python

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

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

    # Initialize request argument(s)
    data_scan = dataplex_v1.DataScan()
    data_scan.data_quality_spec.rules.dimension = "dimension_value"
    data_scan.data.entity = "entity_value"

    request = dataplex_v1.CreateDataScanRequest(
        parent="parent_value",
        data_scan=data_scan,
        data_scan_id="data_scan_id_value",
    )

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

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

    response = operation.result()

    # Handle the response
    print(response)

Ruby

Ruby

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

require "google/cloud/dataplex/v1"

##
# Snippet for the create_data_scan call in the DataScanService 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::DataScanService::Client#create_data_scan.
#
def create_data_scan
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::Dataplex::V1::DataScanService::Client.new

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

  # Call the create_data_scan method.
  result = client.create_data_scan 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

データ品質スキャンを作成するには、dataScans.create メソッドを使用します。

次のリクエストでは、1 回限りのデータ品質スキャンを作成しています。

POST https://dataplex.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/dataScans?data_scan_id=DATASCAN_ID

{
"data": {
  "resource": "//bigquery.googleapis.com/projects/PROJECT_ID/datasets/DATASET_ID/tables/TABLE_ID"
},
"type": "DATA_QUALITY",
"executionSpec": {
  "trigger": {
    "oneTime": {
      "ttl_after_scan_completion": "120s"
    }
  }
},
"dataQualitySpec": {
  "rules": [
    {
      "nonNullExpectation": {},
      "column": "COLUMN_NAME",
      "dimension": "DIMENSION",
      "threshold": 1
    }
  ]
}
}

次のように置き換えます。

  • PROJECT_ID: プロジェクト ID。
  • LOCATION: データ品質スキャンを作成するリージョン。
  • DATASCAN_ID: データ品質スキャンの ID。
  • DATASET_ID: BigQuery データセットの ID。
  • TABLE_ID: BigQuery テーブルの ID。
  • COLUMN_NAME: ルールの列名。
  • DIMENSION: ルールのディメンション(VALIDITY など)。

データ プロファイリング スキャンの結果に基づくルールの推奨事項を使用してデータ品質スキャンのルールを作成する場合は、データ プロファイリング スキャンで dataScans.jobs.generateDataQualityRules メソッドを呼び出して推奨事項を取得します。

データ品質スキャンを実行する

コンソール

  1. Google Cloud コンソールの BigQuery の [メタデータのキュレーション] ページで、[データのプロファイリングと品質] タブに移動します。

    [データのプロファイリングと品質] に移動

  2. 実行するデータ品質スキャンをクリックします。

  3. [今すぐ実行] をクリックします。

gcloud

データ品質スキャンを実行するには、gcloud dataplex datascans run コマンドを使用します。

gcloud dataplex datascans run DATASCAN \
--location=LOCATION \

次の変数を置き換えます。

  • LOCATION: データ品質スキャンが作成された Google Cloud リージョン。
  • DATASCAN: データ品質スキャンの名前。

C#

C#

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

using Google.Cloud.Dataplex.V1;

public sealed partial class GeneratedDataScanServiceClientSnippets
{
    /// <summary>Snippet for RunDataScan</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 RunDataScanRequestObject()
    {
        // Create client
        DataScanServiceClient dataScanServiceClient = DataScanServiceClient.Create();
        // Initialize request argument(s)
        RunDataScanRequest request = new RunDataScanRequest
        {
            DataScanName = DataScanName.FromProjectLocationDataScan("[PROJECT]", "[LOCATION]", "[DATASCAN]"),
        };
        // Make the request
        RunDataScanResponse response = dataScanServiceClient.RunDataScan(request);
    }
}

Go

Go

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


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.NewDataScanClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

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

Java

Java

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

import com.google.cloud.dataplex.v1.DataScanName;
import com.google.cloud.dataplex.v1.DataScanServiceClient;
import com.google.cloud.dataplex.v1.RunDataScanRequest;
import com.google.cloud.dataplex.v1.RunDataScanResponse;

public class SyncRunDataScan {

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

  public static void syncRunDataScan() 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 (DataScanServiceClient dataScanServiceClient = DataScanServiceClient.create()) {
      RunDataScanRequest request =
          RunDataScanRequest.newBuilder()
              .setName(DataScanName.of("[PROJECT]", "[LOCATION]", "[DATASCAN]").toString())
              .build();
      RunDataScanResponse response = dataScanServiceClient.runDataScan(request);
    }
  }
}

Python

Python

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

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

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

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

    # Handle the response
    print(response)

Ruby

Ruby

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

require "google/cloud/dataplex/v1"

##
# Snippet for the run_data_scan call in the DataScanService 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::DataScanService::Client#run_data_scan.
#
def run_data_scan
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::Dataplex::V1::DataScanService::Client.new

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

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

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

REST

データ品質スキャンを実行するには、dataScans.run メソッドを使用します。

データ品質スキャンの結果を表示する

コンソール

  1. Google Cloud コンソールの BigQuery の [メタデータのキュレーション] ページで、[データのプロファイリングと品質] タブに移動します。

    [データのプロファイリングと品質] に移動

  2. データ品質スキャンの名前をクリックします。

    • [概要] セクションには、いつスキャンが実行されたか、各ジョブでスキャンされたレコード数、すべてのデータ品質チェックに合格したか、失敗した場合、失敗したデータ品質チェックの数など、最新のジョブに関する情報が表示されます。

    • [データ品質スキャンの構成] セクションには、スキャンについての詳細が表示されます。

  3. 合格したルールの割合を示すデータ品質スコア、失敗したルール、ジョブログなど、ジョブの詳細情報を確認するには、[ジョブ履歴] タブをクリックします。ジョブ ID をクリックします。

gcloud

データ品質スキャンジョブの結果を表示するには、gcloud dataplex datascans jobs describe コマンドを使用します。

gcloud dataplex datascans jobs describe JOB \
--location=LOCATION \
--datascan=DATASCAN \
--view=FULL

次の変数を置き換えます。

  • JOB: データ品質スキャンジョブのジョブ ID。
  • LOCATION: データ品質スキャンが作成された Google Cloud リージョン。
  • DATASCAN: ジョブが属するデータ品質スキャンの名前。
  • --view=FULL: スキャンジョブの結果を表示するには、FULL を指定します。

C#

C#

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

using Google.Cloud.Dataplex.V1;

public sealed partial class GeneratedDataScanServiceClientSnippets
{
    /// <summary>Snippet for GetDataScan</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 GetDataScanRequestObject()
    {
        // Create client
        DataScanServiceClient dataScanServiceClient = DataScanServiceClient.Create();
        // Initialize request argument(s)
        GetDataScanRequest request = new GetDataScanRequest
        {
            DataScanName = DataScanName.FromProjectLocationDataScan("[PROJECT]", "[LOCATION]", "[DATASCAN]"),
            View = GetDataScanRequest.Types.DataScanView.Unspecified,
        };
        // Make the request
        DataScan response = dataScanServiceClient.GetDataScan(request);
    }
}

Go

Go

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


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.NewDataScanClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

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

Java

Java

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

import com.google.cloud.dataplex.v1.DataScan;
import com.google.cloud.dataplex.v1.DataScanName;
import com.google.cloud.dataplex.v1.DataScanServiceClient;
import com.google.cloud.dataplex.v1.GetDataScanRequest;

public class SyncGetDataScan {

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

  public static void syncGetDataScan() 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 (DataScanServiceClient dataScanServiceClient = DataScanServiceClient.create()) {
      GetDataScanRequest request =
          GetDataScanRequest.newBuilder()
              .setName(DataScanName.of("[PROJECT]", "[LOCATION]", "[DATASCAN]").toString())
              .build();
      DataScan response = dataScanServiceClient.getDataScan(request);
    }
  }
}

Python

Python

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

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

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

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

    # Handle the response
    print(response)

Ruby

Ruby

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

require "google/cloud/dataplex/v1"

##
# Snippet for the get_data_scan call in the DataScanService 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::DataScanService::Client#get_data_scan.
#
def get_data_scan
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::Dataplex::V1::DataScanService::Client.new

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

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

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

REST

データ品質スキャンの結果を表示するには、dataScans.get メソッドを使用します。

公開された結果を表示する

データ品質スキャンの結果が Dataplex Universal Catalog メタデータとして公開されている場合は、Google Cloud コンソールの BigQuery ページと Dataplex Universal Catalog ページにあるソーステーブルの [データ品質] タブで最新のスキャン結果を確認できます。

  1. Google Cloud コンソールで、[BigQuery] ページに移動します。

    BigQuery に移動

  2. 左側のペインで、 エクスプローラをクリックします。

    ハイライト表示された [エクスプローラ] ペインのボタン。

    左側のペインが表示されていない場合は、 [左ペインを開く] をクリックしてペインを開きます。

  3. [エクスプローラ] ペインで、[データセット] をクリックし、目的のデータセットをクリックします。

  4. [概要] > [テーブル] をクリックし、データ品質スキャン結果を表示するテーブルを選択します。

  5. [データ品質] タブをクリックします。

    最後に公開された結果が表示されます。

スキャン結果の履歴を表示する

Dataplex Universal Catalog は、過去 300 件のジョブ、または過去 1 年間のいずれか早いほうのデータ プロファイルのスキャン履歴を保存します。

コンソール

  1. Google Cloud コンソールの BigQuery の [メタデータのキュレーション] ページで、[データのプロファイリングと品質] タブに移動します。

    [データのプロファイリングと品質] に移動

  2. データ品質スキャンの名前をクリックします。

  3. [ジョブ履歴] タブをクリックします。

    [ジョブ履歴] タブには、各ジョブでスキャンされたレコード数、ジョブのステータス、ジョブの実行時刻、各ルールの合否など、過去のジョブに関する情報が表示されます。

  4. ジョブについての詳細情報を表示するには、[ジョブ ID] 列でジョブをクリックします。

gcloud

過去のデータ品質スキャンジョブを表示するには、gcloud dataplex datascans jobs list コマンドを使用します。

gcloud dataplex datascans jobs list \
--location=LOCATION \
--datascan=DATASCAN \

次の変数を置き換えます。

  • LOCATION: データ品質スキャンが作成された Google Cloud リージョン。
  • DATASCAN: 過去のジョブを表示するデータ品質スキャンの名前。

C#

C#

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

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

public sealed partial class GeneratedDataScanServiceClientSnippets
{
    /// <summary>Snippet for ListDataScanJobs</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 ListDataScanJobsRequestObject()
    {
        // Create client
        DataScanServiceClient dataScanServiceClient = DataScanServiceClient.Create();
        // Initialize request argument(s)
        ListDataScanJobsRequest request = new ListDataScanJobsRequest
        {
            ParentAsDataScanName = DataScanName.FromProjectLocationDataScan("[PROJECT]", "[LOCATION]", "[DATASCAN]"),
            Filter = "",
        };
        // Make the request
        PagedEnumerable<ListDataScanJobsResponse, DataScanJob> response = dataScanServiceClient.ListDataScanJobs(request);

        // Iterate over all response items, lazily performing RPCs as required
        foreach (DataScanJob 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 (ListDataScanJobsResponse page in response.AsRawResponses())
        {
            // Do something with each page of items
            Console.WriteLine("A page of results:");
            foreach (DataScanJob 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<DataScanJob> 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 (DataScanJob 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

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


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.NewDataScanClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &dataplexpb.ListDataScanJobsRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/dataplex/apiv1/dataplexpb#ListDataScanJobsRequest.
	}
	it := c.ListDataScanJobs(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.ListDataScanJobsResponse)
	}
}

Java

Java

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

import com.google.cloud.dataplex.v1.DataScanJob;
import com.google.cloud.dataplex.v1.DataScanName;
import com.google.cloud.dataplex.v1.DataScanServiceClient;
import com.google.cloud.dataplex.v1.ListDataScanJobsRequest;

public class SyncListDataScanJobs {

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

  public static void syncListDataScanJobs() 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 (DataScanServiceClient dataScanServiceClient = DataScanServiceClient.create()) {
      ListDataScanJobsRequest request =
          ListDataScanJobsRequest.newBuilder()
              .setParent(DataScanName.of("[PROJECT]", "[LOCATION]", "[DATASCAN]").toString())
              .setPageSize(883849137)
              .setPageToken("pageToken873572522")
              .setFilter("filter-1274492040")
              .build();
      for (DataScanJob element : dataScanServiceClient.listDataScanJobs(request).iterateAll()) {
        // doThingsWith(element);
      }
    }
  }
}

Python

Python

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

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

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

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

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

Ruby

Ruby

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

require "google/cloud/dataplex/v1"

##
# Snippet for the list_data_scan_jobs call in the DataScanService 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::DataScanService::Client#list_data_scan_jobs.
#
def list_data_scan_jobs
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::Dataplex::V1::DataScanService::Client.new

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

  # Call the list_data_scan_jobs method.
  result = client.list_data_scan_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::DataScanJob.
    p item
  end
end

REST

データ品質スキャンジョブの履歴を表示するには、dataScans.jobs.list メソッドを使用します。

データ品質スキャンの結果へのアクセスを許可する

組織内のユーザーがスキャン結果を表示できるようにするには、次の操作を行います。

  1. Google Cloud コンソールの BigQuery の [メタデータのキュレーション] ページで、[データのプロファイリングと品質] タブに移動します。

    [データのプロファイリングと品質] に移動

  2. 結果を共有するデータ品質スキャンをクリックします。

  3. [権限] タブをクリックします。

  4. 手順は次のとおりです。

    • プリンシパルにアクセス権を付与するには、[ アクセス権を付与] をクリックします。関連するプリンシパルに Dataplex DataScan データ閲覧者ロールを付与します。
    • プリンシパルからアクセス権を削除するには、Dataplex DataScan データ閲覧者ロールを削除するプリンシパルを選択します。[アクセス権を削除] をクリックし、プロンプトが表示されたら確定します。

データ品質エラーのトラブルシューティング

データ品質エラーのアラートは、Cloud Logging のログを使用して設定できます。サンプルクエリなどの詳細については、Cloud Logging でアラートを設定するをご覧ください。

行レベルのルールがエラーになるジョブごとに、Dataplex Universal Catalog はエラーになったレコードを取得するクエリを提供します。このクエリを実行して、ルールと一致しなかったレコードを表示します。

コンソール

  1. Google Cloud コンソールの BigQuery の [メタデータのキュレーション] ページで、[データのプロファイリングと品質] タブに移動します。

    [データのプロファイリングと品質] に移動

  2. レコードのトラブルシューティングを行うデータ品質スキャンの名前をクリックします。

  3. [ジョブ履歴] タブをクリックします。

  4. データ品質エラーを特定したジョブのジョブ ID をクリックします。

  5. 表示されたジョブ ウィンドウの [ルール] セクションで、[失敗したレコードを取得するクエリ] 列を見つけます。失敗したルールの [クエリをクリップボードにコピー] をクリックします。

  6. BigQuery でクエリを実行して、ジョブの失敗の原因となったレコードを確認します。

gcloud

サポートされていません。

REST

  1. データ品質エラーが特定されたジョブを取得するには、dataScans.get メソッドを使用します。

    レスポンス オブジェクトの failingRowsQuery フィールドにクエリが表示されます。

  2. BigQuery でクエリを実行して、ジョブの失敗の原因となったレコードを確認します。

Dataplex Universal Catalog は、ルール作成時にデバッグクエリが含まれている場合は、そのデバッグクエリも実行します。デバッグクエリの結果は、各ルールの出力に含まれます。この機能はプレビュー版です。

コンソール

サポートされていません。

gcloud

サポートされていません。

REST

データ品質エラーが特定されたジョブを取得するには、dataScans.get メソッドを使用します。レスポンス オブジェクトの debugQueriesResultSets フィールドにデバッグクエリの結果が表示されます。

特定のテーブルのデータ品質スキャンを管理する

このドキュメントの手順では、Google Cloud コンソールの BigQuery の [メタデータのキュレーション] > [データ プロファイリングと品質] ページを使用して、プロジェクト全体でデータ品質スキャンを管理する方法について説明します。

特定のテーブルを操作するときに、データ品質スキャンを作成して管理することもできます。 Google Cloud コンソールのテーブルの BigQuery ページで、[データ品質] タブを使用します。手順は次のとおりです。

  1. Google Cloud コンソールで、[BigQuery] ページに移動します。

    [BigQuery] に移動

    [エクスプローラ] ペイン(左側のペイン)で、[データセット] をクリックし、目的のデータセットをクリックします。 [概要] > [テーブル] をクリックし、データ品質スキャン結果を表示するテーブルを選択します。

  2. [データ品質] タブをクリックします。

  3. 結果が Dataplex Universal Catalog メタデータとして公開されているデータ品質スキャンがテーブルにあるかどうかに応じて、次の方法でテーブルのデータ品質スキャンを操作できます。

    • データ品質スキャンの結果が公開されている: 最新のスキャン結果がページに表示されます。

      このテーブルのデータ品質スキャンを管理するには、[データ品質スキャン] をクリックし、次のオプションから選択します。

      • 新しいスキャンを作成: 新しいデータ品質スキャンを作成します。詳細については、このドキュメントのデータ品質スキャンを作成するをご覧ください。テーブルの詳細ページからスキャンを作成すると、テーブルが事前に選択されます。

      • 今すぐ実行: スキャンを実行します。

      • スキャン構成を編集: 表示名、フィルタ、スケジュールなどの設定を編集します。

        データ品質ルールを編集するには、[データ品質] タブで [ルール] タブをクリックします。[ルールの変更] をクリックします。ルールを更新して、[保存] をクリックします。

      • スキャン権限を管理: スキャン結果にアクセスできるユーザーを制御します。詳細については、このドキュメントのデータ品質スキャンの結果へのアクセスを許可するをご覧ください。

      • 過去の結果を見る: 以前のデータ品質スキャンジョブの詳細情報を表示します。詳細については、このドキュメントのデータ品質スキャン結果を表示する過去のスキャン結果を表示するのセクションをご覧ください。

      • すべてのスキャンを表示: このテーブルに適用されるデータ品質スキャンのリストを表示します。

    • データ品質スキャンの結果が公開されていない: 次のオプションから選択します。

      • データ品質スキャンの作成: 新しいデータ品質スキャンを作成します。詳細については、このドキュメントのデータ品質スキャンを作成するをご覧ください。テーブルの詳細ページからスキャンを作成すると、テーブルが事前に選択されます。

      • 既存のスキャンを表示: このテーブルに適用されるデータ品質スキャンの一覧を表示します。

テーブルのデータ品質スキャンを表示する

特定のテーブルに適用されるデータ品質スキャンを表示する手順は次のとおりです。

  1. Google Cloud コンソールの BigQuery の [メタデータのキュレーション] ページで、[データのプロファイリングと品質] タブに移動します。

    [データのプロファイリングと品質] に移動

  2. テーブル名とスキャンタイプでリストをフィルタします。

データ品質スキャンを更新する

既存のデータ品質スキャンのさまざまな設定(表示名、フィルタ、スケジュール、データ品質ルールなど)を編集できます。

コンソール

  1. Google Cloud コンソールの BigQuery の [メタデータのキュレーション] ページで、[データのプロファイリングと品質] タブに移動します。

    [データのプロファイリングと品質] に移動

  2. データ品質スキャンの名前をクリックします。

  3. 表示名、フィルタ、スケジュールなどの設定を編集するには、[編集] をクリックします。値を編集し、[保存] をクリックします。

  4. データ品質ルールを編集するには、スキャンの詳細ページで [現在のルール] タブをクリックします。[ルールの変更] をクリックします。ルールを更新して、[保存] をクリックします。

gcloud

データ品質スキャンの説明を更新するには、gcloud dataplex datascans update data-quality コマンドを使用します。

gcloud dataplex datascans update data-quality DATASCAN \
--location=LOCATION \
--description=DESCRIPTION

次のように置き換えます。

  • DATASCAN: 更新するデータ品質スキャンの名前。
  • LOCATION: データ品質スキャンが作成された Google Cloud リージョン。
  • DESCRIPTION: データ品質スキャンの新しい説明。

C#

C#

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

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

public sealed partial class GeneratedDataScanServiceClientSnippets
{
    /// <summary>Snippet for UpdateDataScan</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 UpdateDataScanRequestObject()
    {
        // Create client
        DataScanServiceClient dataScanServiceClient = DataScanServiceClient.Create();
        // Initialize request argument(s)
        UpdateDataScanRequest request = new UpdateDataScanRequest
        {
            DataScan = new DataScan(),
            UpdateMask = new FieldMask(),
            ValidateOnly = false,
        };
        // Make the request
        Operation<DataScan, OperationMetadata> response = dataScanServiceClient.UpdateDataScan(request);

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

Go

Go

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


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.NewDataScanClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &dataplexpb.UpdateDataScanRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/dataplex/apiv1/dataplexpb#UpdateDataScanRequest.
	}
	op, err := c.UpdateDataScan(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

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

import com.google.cloud.dataplex.v1.DataScan;
import com.google.cloud.dataplex.v1.DataScanServiceClient;
import com.google.cloud.dataplex.v1.UpdateDataScanRequest;
import com.google.protobuf.FieldMask;

public class SyncUpdateDataScan {

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

  public static void syncUpdateDataScan() 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 (DataScanServiceClient dataScanServiceClient = DataScanServiceClient.create()) {
      UpdateDataScanRequest request =
          UpdateDataScanRequest.newBuilder()
              .setDataScan(DataScan.newBuilder().build())
              .setUpdateMask(FieldMask.newBuilder().build())
              .setValidateOnly(true)
              .build();
      DataScan response = dataScanServiceClient.updateDataScanAsync(request).get();
    }
  }
}

Python

Python

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

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

    # Initialize request argument(s)
    data_scan = dataplex_v1.DataScan()
    data_scan.data_quality_spec.rules.dimension = "dimension_value"
    data_scan.data.entity = "entity_value"

    request = dataplex_v1.UpdateDataScanRequest(
        data_scan=data_scan,
    )

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

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

    response = operation.result()

    # Handle the response
    print(response)

Ruby

Ruby

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

require "google/cloud/dataplex/v1"

##
# Snippet for the update_data_scan call in the DataScanService 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::DataScanService::Client#update_data_scan.
#
def update_data_scan
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::Dataplex::V1::DataScanService::Client.new

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

  # Call the update_data_scan method.
  result = client.update_data_scan 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

データ品質スキャンを編集するには、dataScans.patch メソッドを使用します。

データ品質スキャンを削除する

コンソール

コンソール

  1. Google Cloud コンソールの BigQuery の [メタデータのキュレーション] ページで、[データのプロファイリングと品質] タブに移動します。

    [データのプロファイリングと品質] に移動

  2. 削除するスキャンをクリックします。

  3. [削除] をクリックし、プロンプトが表示されたら確定します。

gcloud

gcloud

データ品質スキャンを削除するには、gcloud dataplex datascans delete コマンドを使用します。

gcloud dataplex datascans delete DATASCAN \
--location=LOCATION \
--async

次の変数を置き換えます。

  • DATASCAN: 削除するデータ品質スキャンの名前。
  • LOCATION: データ品質スキャンが作成された Google Cloud リージョン。

C#

C#

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

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

public sealed partial class GeneratedDataScanServiceClientSnippets
{
    /// <summary>Snippet for DeleteDataScan</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 DeleteDataScanRequestObject()
    {
        // Create client
        DataScanServiceClient dataScanServiceClient = DataScanServiceClient.Create();
        // Initialize request argument(s)
        DeleteDataScanRequest request = new DeleteDataScanRequest
        {
            DataScanName = DataScanName.FromProjectLocationDataScan("[PROJECT]", "[LOCATION]", "[DATASCAN]"),
            Force = false,
        };
        // Make the request
        Operation<Empty, OperationMetadata> response = dataScanServiceClient.DeleteDataScan(request);

        // Poll until the returned long-running operation is complete
        Operation<Empty, OperationMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        Empty result = completedResponse.Result;

        // Or get the name of the operation
        string operationName = response.Name;
        // This name can be stored, then the long-running operation retrieved later by name
        Operation<Empty, OperationMetadata> retrievedResponse = dataScanServiceClient.PollOnceDeleteDataScan(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            Empty retrievedResult = retrievedResponse.Result;
        }
    }
}

Go

Go

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


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.NewDataScanClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

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

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

Java

Java

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

import com.google.cloud.dataplex.v1.DataScanName;
import com.google.cloud.dataplex.v1.DataScanServiceClient;
import com.google.cloud.dataplex.v1.DeleteDataScanRequest;
import com.google.protobuf.Empty;

public class SyncDeleteDataScan {

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

  public static void syncDeleteDataScan() 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 (DataScanServiceClient dataScanServiceClient = DataScanServiceClient.create()) {
      DeleteDataScanRequest request =
          DeleteDataScanRequest.newBuilder()
              .setName(DataScanName.of("[PROJECT]", "[LOCATION]", "[DATASCAN]").toString())
              .setForce(true)
              .build();
      dataScanServiceClient.deleteDataScanAsync(request).get();
    }
  }
}

Python

Python

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

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


def sample_delete_data_scan():
    # Create a client
    client = dataplex_v1.DataScanServiceClient()

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

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

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

    response = operation.result()

    # Handle the response
    print(response)

Ruby

Ruby

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

require "google/cloud/dataplex/v1"

##
# Snippet for the delete_data_scan call in the DataScanService 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::DataScanService::Client#delete_data_scan.
#
def delete_data_scan
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::Dataplex::V1::DataScanService::Client.new

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

  # Call the delete_data_scan method.
  result = client.delete_data_scan 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

REST

データ品質スキャンを削除するには、dataScans.delete メソッドを使用します。

次のステップ