分析数据

本文档介绍了如何使用数据分析扫描来更好地了解数据。 BigQuery 使用 Dataplex Universal Catalog 分析数据的统计特征,例如平均值、唯一值和最大值。Dataplex Universal Catalog 还会根据这些信息建议数据质量检查规则

如需详细了解数据分析,请参阅数据分析简介

准备工作

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

所需的角色

如需获得创建和管理数据分析扫描所需的权限,请让管理员向您授予资源(例如项目或表)的以下 IAM 角色:

  • 创建、运行、更新和删除数据分析扫描: 针对包含数据扫描的项目的 Dataplex DataScan Editor (roles/dataplex.dataScanEditor) 角色。
  • 如需允许 Dataplex Universal Catalog 针对 BigQuery 数据运行数据分析扫描,请为 Dataplex Universal Catalog 服务账号授予以下角色: 运行扫描的项目中的 BigQuery Job User (roles/bigquery.jobUser) 角色;被扫描的表中的 BigQuery Data Viewer (roles/bigquery.dataViewer) 角色。
  • 如需针对使用 Cloud Storage 数据的 BigQuery 外部表运行数据分析扫描,请为 Dataplex Universal Catalog 服务账号授予 Cloud Storage 存储桶的 Storage Object Viewer (roles/storage.objectViewer) 和 Storage Legacy Bucket Reader (roles/storage.legacyBucketReader) 角色。
  • 查看数据分析扫描结果、作业和历史记录: 包含数据扫描的项目的 Dataplex DataScan Viewer (roles/dataplex.dataScanViewer) 角色。
  • 将数据分析扫描结果导出到 BigQuery 表:针对表的 BigQuery Data Editor (roles/bigquery.dataEditor) 角色。
  • 将数据分析扫描结果发布到 Dataplex Universal Catalog:针对 @bigquery 条目组的 Dataplex Catalog Editor (roles/dataplex.catalogEditor) 角色。
  • 数据分析标签页中查看 BigQuery 中已发布的数据分析文件扫描结果: 表的 BigQuery Data Viewer (roles/bigquery.dataViewer) 角色。

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

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

所需权限

如果您使用的是自定义角色,则需要授予以下 IAM 权限:

  • 创建、运行、更新和删除数据分析扫描:
    • 项目的 dataplex.datascans.create 权限 - 创建 DataScan
    • 数据扫描的 dataplex.datascans.update 权限 - 更新 DataScan 的说明
    • 数据扫描的 dataplex.datascans.delete 权限 - 删除 DataScan
    • 数据扫描的 dataplex.datascans.run 权限 - 运行 DataScan
    • 数据扫描的 dataplex.datascans.get 权限 - 查看 DataScan 详细信息(不包括结果)
    • 项目的 dataplex.datascans.list 权限 - 列出 DataScan
    • 数据扫描作业的 dataplex.dataScanJobs.get 权限 - 读取 DataScan 作业资源
    • 数据扫描的 dataplex.dataScanJobs.list 权限 - 列出项目中的数据扫描作业资源
  • 允许 Dataplex Universal Catalog 针对 BigQuery 数据运行数据分析扫描:
    • 项目的 bigquery.jobs.create 权限 - 运行作业
    • 表的 bigquery.tables.get 权限 - 获取表元数据
    • 表的 bigquery.tables.getData 权限 - 获取表数据
  • 针对使用 Cloud Storage 数据的 BigQuery 外部表运行数据分析扫描:
    • 存储桶的 storage.buckets.get 权限 - 读取存储桶元数据
    • 对象的 storage.objects.get 权限 - 读取对象数据
  • 查看数据分析扫描结果、作业和历史记录:
    • 数据扫描的 dataplex.datascans.getData 权限 - 查看 DataScan 详细信息(包括结果)
    • 项目的 dataplex.datascans.list 权限 - 列出 DataScan
    • 数据扫描作业的 dataplex.dataScanJobs.get 权限 - 读取 DataScan 作业资源
    • 数据扫描的 dataplex.dataScanJobs.list 权限 - 列出项目中的数据扫描作业资源
  • 将数据分析扫描结果导出到 BigQuery 表:
    • 数据集的 bigquery.tables.create 权限 - 创建表
    • 表的 bigquery.tables.updateData 权限 - 将数据写入表
  • 将数据分析扫描结果发布到 Dataplex Universal Catalog:
    • 条目组的 dataplex.entryGroups.useDataProfileAspect 权限 - 允许 Dataplex Universal Catalog 数据分析扫描将其结果保存到 Dataplex Universal Catalog
    • 此外,您还需要以下权限之一:
      • 表的 bigquery.tables.update 权限 - 更新表元数据
      • 条目的 dataplex.entries.update 权限 - 更新条目
  • 在 BigQuery 或 Dataplex Universal Catalog 中查看已发布的数据分析结果:
    • 表的 bigquery.tables.get 权限 - 获取表元数据
    • 表的 bigquery.tables.getData 权限 - 获取表数据

如果某个表使用 BigQuery 行级安全性,则 Dataplex Universal Catalog 只能扫描对 Dataplex Universal Catalog 服务账号可见的行。如需允许 Dataplex Universal Catalog 扫描所有行,请将其服务账号添加到谓词为 TRUE 的行过滤条件中。

如果某个表使用 BigQuery 列级安全性,则 Dataplex Universal Catalog 需要有权扫描受保护的列。如需授予访问权限,请为 Dataplex Universal Catalog 服务账号授予表中所用所有政策标记的 Data Catalog Fine-Grained Reader (roles/datacatalog.fineGrainedReader) 角色。创建或更新数据扫描的用户也需要拥有这些受保护列的权限。

向 Dataplex Universal Catalog 服务账号授予角色

为了运行数据分析扫描,Dataplex Universal Catalog 使用的服务账号需要拥有运行 BigQuery 作业和读取 BigQuery 表数据的权限。如需授予所需的角色,请按以下步骤操作:

  1. 获取 Dataplex Universal Catalog 服务账号的邮箱。如果您之前未在此项目中创建数据分析或数据质量扫描,请运行以下 gcloud 命令以生成服务身份:

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

    该命令会返回服务账号邮箱,其格式如下:service-PROJECT_NUMBER@gcp-sa-dataplex.iam.gserviceaccount.com

    如果服务账号已存在,您可以在 Google Cloud 控制台的 IAM 页面上查看名称中包含 Dataplex 的主账号,找到该服务账号的邮箱。

  2. 向服务账号授予您项目的 BigQuery Job User (roles/bigquery.jobUser) 角色。此角色可让服务账号运行 BigQuery 作业以进行扫描。

    gcloud projects add-iam-policy-binding PROJECT_ID \
        --member="serviceAccount:service-PROJECT_NUMBER@gcp-sa-dataplex.iam.gserviceaccount.com" \
        --role="roles/bigquery.jobUser"
    

    替换以下内容:

    • PROJECT_ID:您的 Google Cloud 项目 ID。
    • service-PROJECT_NUMBER@gcp-sa-dataplex.iam.gserviceaccount.com:Dataplex Universal Catalog 服务账号的邮箱。
  3. 向服务账号授予您要分析的每个表的 BigQuery Data Viewer (roles/bigquery.dataViewer) 角色。此角色可授予对表的只读权限。

    gcloud bigquery tables add-iam-policy-binding DATASET_ID.TABLE_ID \
        --member="serviceAccount:service-PROJECT_NUMBER@gcp-sa-dataplex.iam.gserviceaccount.com" \
        --role="roles/bigquery.dataViewer"
    

    替换以下内容:

    • DATASET_ID:包含相应表的数据集的 ID。
    • TABLE_ID:要分析的表的 ID。
    • service-PROJECT_NUMBER@gcp-sa-dataplex.iam.gserviceaccount.com:Dataplex Universal Catalog 服务账号的邮箱。

      创建数据分析扫描

      控制台

      1. 在 Google Cloud 控制台中的 BigQuery 元数据整理页面上,前往数据分析和质量评估标签页。

        前往“数据分析和质量评估”

      2. 点击创建数据分析扫描

      3. 可选:输入显示名称

      4. 输入 ID。请参阅资源命名惯例

      5. (可选)输入说明

      6. 字段中,点击浏览。选择要扫描的表,然后点击选择

        对于多区域数据集中的表,请选择要在其中创建数据扫描的区域。

        如需浏览在 Dataplex Universal Catalog 数据湖中整理的表,请点击在 Dataplex 数据湖中浏览

      7. 范围字段中,选择增量所有数据

        • 如果您选择增量数据,请在时间戳列字段中,从 BigQuery 表中选择类型为 DATETIMESTAMP 且可随新记录的添加而递增的列,该列可用于识别新记录。对于按 DATETIMESTAMP 类型的列进行分区的表,我们建议将分区列用作时间戳字段。
      8. 可选:如需过滤数据,请执行以下任一操作:

        • 如需按行过滤,请点击选中过滤行复选框。 输入一个有效的 SQL 表达式,该表达式可用于 GoogleSQL 语法中的 WHERE 子句。例如:col1 >= 0

          过滤条件可以是多个列的 SQL 条件的组合。例如:col1 >= 0 AND col2 < 10

        • 如需按列过滤,请选中过滤列复选框。

          • 如需在数据分析扫描中包含列,请在包含列字段中点击浏览。选择要添加的列,然后点击选择

          • 如需从数据分析扫描中排除列,请在排除列字段中点击浏览。选择要排除的列,然后点击选择

      9. 如需对数据分析扫描应用采样,请在采样规模列表中选择采样百分比。选择一个范围介于 0.0% 到 100.0% 之间的百分比值,最多精确到小数点后 3 位。

        • 对于较大的数据集,请选择一个较低的采样百分比。例如,对于一个 1 PB 的表,如果您输入的值介于 0.1% 到 1.0% 之间,则数据分析会采样 1-10 TB 的数据。

        • 采样数据中必须至少有 100 条记录才能返回结果。

        • 对于增量数据扫描,数据分析扫描会对最新增量应用采样。

      10. 可选:在Google Cloud 控制台中源表的 BigQuery 和 Dataplex Universal Catalog 页面中发布数据分析扫描结果。选中将结果发布到 BigQuery 和 Dataplex Catalog 复选框。

        您可以在源表的 BigQuery 和 Dataplex Universal Catalog 页面中的数据分析标签页上查看最新扫描结果。如需使用户能够访问已发布的扫描结果,请参阅本文档的授予对数据分析扫描结果的访问权限部分。

        在以下情况下,发布选项可能不可用:

        • 您没有相应表的所需权限。
        • 另一数据质量扫描已设置为发布结果。
      11. 时间表部分中,选择以下选项之一:

        • 重复:按时间表(每小时、每天、每周、每月或自定义)运行数据分析扫描。指定扫描的运行频率和时间。如果您选择自定义,请使用 cron 格式指定时间表。

        • 按需:按需运行数据分析扫描。

      12. 点击继续

      13. 可选:将扫描结果导出到 BigQuery 标准表。在将扫描结果导出到 BigQuery 表部分中,执行以下操作:

        1. 选择 BigQuery 数据集字段中,点击浏览。选择一个 BigQuery 数据集,用于存储数据分析扫描结果。

        2. BigQuery 表字段中,指定用于存储数据分析扫描结果的表。如果您使用的是现有表,请确保该表与导出表架构兼容。如果指定的表不存在,Dataplex Universal Catalog 会为您创建该表。

      14. 可选:添加标签。标签是键值对,可用于将相关对象组合在一起或者与其他 Google Cloud 资源组合在一起。

      15. 如需创建扫描,请点击创建

        如果您将时间表设置为“按需”,还可以点击运行扫描立即运行扫描。

      gcloud

      如需创建数据分析扫描,请使用 gcloud dataplex datascans create data-profile 命令

      如果源数据在 Dataplex Universal Catalog 数据湖中整理,请添加 --data-source-entity 标志:

      gcloud dataplex datascans create data-profile DATASCAN \
      --location=LOCATION \
      --data-source-entity=DATA_SOURCE_ENTITY
      

      如果源数据未在 Dataplex Universal Catalog 数据湖中整理,请添加 --data-source-resource 标志:

      gcloud dataplex datascans create data-profile DATASCAN \
      --location=LOCATION \
      --data-source-resource=DATA_SOURCE_RESOURCE
      

      执行以下变量替换操作:

      • DATASCAN:数据分析扫描的名称。
      • LOCATION:要在其中创建数据分析扫描的 Google Cloud 区域。
      • 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#

      在尝试此示例之前,请按照 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 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

      在尝试此示例之前,请按照 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.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

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

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

      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();
          }
        }
      }

      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_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

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

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

      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 方法

      创建多个数据分析扫描

      您可以使用 Google Cloud 控制台,同时为 BigQuery 数据集中的多个表配置数据分析扫描。

      1. 在 Google Cloud 控制台中的 BigQuery 元数据整理页面上,前往数据分析和质量评估标签页。

        前往“数据分析和质量评估”

      2. 点击创建数据分析扫描

      3. 选择多次数据分析扫描选项。

      4. 输入 ID 前缀。Dataplex Universal Catalog 会使用提供的前缀和唯一后缀自动生成扫描 ID。

      5. 为所有数据分析扫描输入说明

      6. 数据集字段中,点击浏览。选择一个数据集以从中选择表。点击选择

      7. 如果数据集是多区域级数据集,请选择要在其中创建数据分析扫描的区域

      8. 配置扫描的常用设置:

        1. 范围字段中,选择增量所有数据

        2. 如需对数据分析扫描应用采样,请在采样规模列表中选择采样百分比。

          选择一个介于 0.0% 到 100.0% 之间的百分比值,最多精确到小数点后 3 位。

        3. 可选:在Google Cloud 控制台中源表的 BigQuery 和 Dataplex Universal Catalog 页面中发布数据分析扫描结果。选中将结果发布到 BigQuery 和 Dataplex Catalog 复选框。

          您可以在源表的 BigQuery 和 Dataplex Universal Catalog 页面中的数据分析标签页上查看最新扫描结果。如需使用户能够访问已发布的扫描结果,请参阅本文档的授予对数据分析扫描结果的访问权限部分。

        4. 时间表部分中,选择以下选项之一:

          • 重复:按时间表(每小时、每天、每周、每月或自定义)运行数据分析扫描。指定扫描的运行频率和时间。如果您选择自定义,请使用 cron 格式指定时间表。

          • 按需:按需运行数据分析扫描。

      9. 点击继续

      10. 选择表字段中,点击浏览。选择一个或多个要扫描的表,然后点击选择

      11. 点击继续

      12. 可选:将扫描结果导出到 BigQuery 标准表。在将扫描结果导出到 BigQuery 表部分中,执行以下操作:

        1. 选择 BigQuery 数据集字段中,点击浏览。选择一个 BigQuery 数据集,用于存储数据分析扫描结果。

        2. BigQuery 表字段中,指定用于存储数据分析扫描结果的表。如果您使用的是现有表,请确保该表与导出表架构兼容。如果指定的表不存在,Dataplex Universal Catalog 会为您创建该表。

          Dataplex Universal Catalog 会为所有数据分析扫描使用同一结果表。

      13. 可选:添加标签。标签是键值对,可用于将相关对象组合在一起或者与其他 Google Cloud 资源组合在一起。

      14. 如需创建扫描,请点击创建

        如果您将时间表设置为“按需”,还可以点击运行扫描立即运行扫描。

      运行数据分析扫描

      控制台

      1. 在 Google Cloud 控制台中的 BigQuery 元数据整理页面上,前往数据分析和质量评估标签页。

        前往“数据分析和质量评估”

      2. 点击要运行的数据分析扫描。
      3. 点击立即运行

      gcloud

      如需运行数据分析扫描,请使用 gcloud dataplex datascans run 命令

      gcloud dataplex datascans run DATASCAN \
      --location=LOCATION
      

      执行以下变量替换操作:

      • DATASCAN:数据分析扫描的名称。
      • LOCATION:在其中创建数据分析扫描的 Google Cloud 区域。

      C#

      C#

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

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

      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

      在尝试此示例之前,请按照 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.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

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

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

      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

      在尝试此示例之前,请按照 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_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

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

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

      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#

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

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

      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

      在尝试此示例之前,请按照 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.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

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

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

      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

      在尝试此示例之前,请按照 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_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

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

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

      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 方法

      查看已发布的结果

      如果数据分析扫描结果发布到 Google Cloud 控制台中的 BigQuery 和 Dataplex Universal Catalog 页面,则您可以在源表的数据分析标签页中查看最新扫描结果。

      1. 在 Google Cloud 控制台中,前往 BigQuery 页面。

        转到 BigQuery

      2. 在左侧窗格中,点击 探索器

        突出显示的“探索器”窗格按钮。

        如果您没有看到左侧窗格,请点击 展开左侧窗格以打开该窗格。

      3. 探索器窗格中,点击数据集,然后点击相应的数据集。

      4. 依次点击概览 >,然后选择要查看其数据分析扫描结果的表。

      5. 点击数据分析标签页。

        系统会显示最新发布的结果。

      查看最近数据分析扫描作业

      控制台

      1. 在 Google Cloud 控制台中的 BigQuery 元数据整理页面上,前往数据分析和质量评估标签页。

        前往“数据分析和质量评估”

      2. 点击数据分析扫描的名称。

      3. 点击最新作业结果标签页。

        如果至少有一次成功完成的运行,最新作业结果标签页会提供有关最近作业的信息。该标签页会列出已扫描的表列,以及在扫描中发现的列的相关统计信息。

      gcloud

      如需查看最近成功的数据分析扫描,请使用 gcloud dataplex datascans describe 命令

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

      执行以下变量替换操作:

      • DATASCAN:要查看其最近作业的数据分析扫描的名称。
      • LOCATION:在其中创建数据分析扫描的 Google Cloud 区域。
      • --view=FULL:如需查看扫描作业结果,请指定 FULL

      REST

      如需查看最近扫描作业,请使用 dataScans.get 方法

      查看历史扫描结果

      Dataplex Universal Catalog 会保存最近 300 个作业或过去一年(以先到者为准)的数据分析扫描历史记录。

      控制台

      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#

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

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

      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

      在尝试此示例之前,请按照 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.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

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

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

      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

      在尝试此示例之前,请按照 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_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

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

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

      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. 按表名称和扫描类型过滤列表。

      授予对数据分析扫描结果的访问权限

      如需让贵组织中的用户查看扫描结果,请执行以下操作:

      1. 在 Google Cloud 控制台中的 BigQuery 元数据整理页面上,前往数据分析和质量评估标签页。

        前往“数据分析和质量评估”

      2. 点击您要共享其结果的数据质量扫描。

      3. 点击权限标签页。

      4. 执行以下操作:

        • 如需向主账号授予访问权限,请点击 授予访问权限。向关联的主账号授予 Dataplex DataScan DataViewer 角色。
        • 如需移除主账号的访问权限,请选择要从中移除 Dataplex DataScan DataViewer 角色的主账号。点击 移除访问权限,然后在系统提示时进行确认。

      管理特定表的数据分析扫描

      本文档中的步骤介绍了如何使用Google Cloud 控制台中的 BigQuery 元数据整理 > 数据分析和质量评估页面来管理项目中的数据分析扫描。

      您还可以在使用特定表时创建和管理数据分析扫描。在 Google Cloud 控制台中,在相应表的 BigQuery 页面上,使用数据分析标签页。执行以下操作:

      1. 在 Google Cloud 控制台中,前往 BigQuery 页面。

        转到 BigQuery

        探索器窗格(位于左侧窗格中)中,点击数据集,然后点击相应的数据集。 现在,依次点击概览 >,然后选择要查看其数据分析扫描结果的表。

      2. 点击数据分析标签页。

      3. 根据表是否具有已发布结果的数据分析扫描,您可以通过以下方式处理表的数据分析扫描:

        • 数据分析扫描结果已发布:页面上会显示最新发布的扫描结果。

          如需管理此表的数据分析扫描,请点击数据分析扫描,然后从以下选项中进行选择:

          • 创建新扫描:创建新的数据分析扫描。如需了解详情,请参阅本文档中的创建数据分析扫描部分。从表的详情页面创建扫描时,系统会预先选择该表。

          • 立即运行:运行扫描。

          • 修改扫描配置:修改设置,包括显示名称、过滤条件、采样规模和时间表。

          • 管理扫描权限:控制哪些人可以访问扫描结果。 如需了解详情,请参阅本文档的授予对数据分析扫描结果的访问权限部分。

          • 查看历史结果:查看之前的数据分析扫描作业的详细信息。如需了解详情,请参阅本文档中的查看数据分析扫描结果查看历史扫描结果部分。

          • 查看所有扫描:查看适用于相应表的数据分析扫描列表。

        • 数据分析扫描结果未发布:点击快速数据分析旁边的菜单,然后从以下选项中进行选择:

          • 自定义数据分析:创建新的数据分析扫描。如需了解详情,请参阅本文档中的创建数据分析扫描部分。从表的详情页面创建扫描时,系统会预先选择该表。

          • 查看先前的分析:查看适用于此表的数据分析扫描的列表。

      更新数据分析扫描

      控制台

      1. 在 Google Cloud 控制台中的 BigQuery 元数据整理页面上,前往数据分析和质量评估标签页。

        前往“数据分析和质量评估”

      2. 点击数据分析扫描的名称。

      3. 点击修改,然后修改相应值。

      4. 点击保存

      gcloud

      如需更新数据分析扫描,请使用 gcloud dataplex datascans update data-profile 命令

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

      执行以下变量替换操作:

      • DATASCAN:要更新的数据分析扫描的名称。
      • LOCATION:在其中创建数据分析扫描的 Google Cloud 区域。
      • DESCRIPTION:数据分析扫描的新说明。

      C#

      C#

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

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

      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

      在尝试此示例之前,请按照 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.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

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

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

      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

      在尝试此示例之前,请按照 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_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

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

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

      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 dataplex datascans delete 命令

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

      执行以下变量替换操作:

      • DATASCAN:要删除的数据分析扫描的名称。
      • LOCATION:在其中创建数据分析扫描的 Google Cloud 区域。

      REST

      如需删除数据分析扫描,请使用 dataScans.delete 方法

      后续步骤