更新商品详情 (v1)

更新数据交换中现有清单的说明。

代码示例

Java

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

如需向 BigQuery 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为客户端库设置身份验证。

import com.google.cloud.bigquery.analyticshub.v1.AnalyticsHubServiceClient;
import com.google.cloud.bigquery.analyticshub.v1.Listing;
import com.google.protobuf.FieldMask;
import java.io.IOException;

public class UpdateListing {

  public static void main(String[] args) throws IOException {
    String projectId = "example-project-id";
    String locationId = "example-location-id";
    String dataExchangeId = "example-data-exchange-id";
    String listingId = "example-listing-id";
    updateListing(projectId, locationId, dataExchangeId, listingId);
  }

  public static void updateListing(
      String projectId, String locationId, String dataExchangeId, String listingId)
      throws IOException {
    try (AnalyticsHubServiceClient client = AnalyticsHubServiceClient.create()) {
      String listingName =
          String.format(
              "projects/%s/locations/%s/dataExchanges/%s/listings/%s",
              projectId, locationId, dataExchangeId, listingId);
      Listing listing =
          Listing.newBuilder()
              .setName(listingName)
              .setDescription("Updated description for the listing")
              .build();
      FieldMask updateMask = FieldMask.newBuilder().addPaths("description").build();

      Listing response = client.updateListing(listing, updateMask);
      System.out.println("Listing updated successfully: " + response.getName());
    }
  }
}

Python

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

如需向 BigQuery 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为客户端库设置身份验证。

from google.api_core import exceptions
from google.cloud import bigquery_analyticshub_v1
from google.protobuf import field_mask_pb2


def update_listing(
    project_id: str,
    location_id: str,
    data_exchange_id: str,
    listing_id: str,
) -> None:
    """Updates an Analytics Hub listing.

    Args:
        project_id: The Google Cloud project ID.
        location_id: The Google Cloud location or region (for example, "us").
        data_exchange_id: The ID of the parent data exchange containing the listing.
        listing_id: The ID of the listing to update.
    """
    client = bigquery_analyticshub_v1.AnalyticsHubServiceClient()

    listing_name = (
        f"projects/{project_id}/locations/{location_id}/"
        f"dataExchanges/{data_exchange_id}/listings/{listing_id}"
    )

    listing = bigquery_analyticshub_v1.Listing(
        name=listing_name,
        description="Updated description for the listing.",
    )
    update_mask = field_mask_pb2.FieldMask(paths=["description"])

    request = bigquery_analyticshub_v1.UpdateListingRequest(
        listing=listing,
        update_mask=update_mask,
    )

    try:
        response = client.update_listing(request=request)
        print(f"Updated listing: {response.name}")
        print(f"Description: {response.description}")
    except exceptions.GoogleAPICallError as error:
        print(f"API call failed: {error}")

后续步骤

如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅Google Cloud 示例浏览器。