목록 업데이트(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 샘플 브라우저 참조하기