עדכון דף האפליקציה (גרסה 1)

עדכון התיאור של דף קיים במאגר נתונים.

דוגמת קוד

Java

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי הוראות ההגדרה של Java במדריך למתחילים של BigQuery באמצעות ספריות לקוח. למידע נוסף, קראו את מאמרי העזרה של BigQuery Java API.

כדי לבצע אימות ב-BigQuery, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

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

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי הוראות ההגדרה של Python במדריך למתחילים של BigQuery באמצעות ספריות לקוח. למידע נוסף, קראו את מאמרי העזרה של BigQuery Python API.

כדי לבצע אימות ב-BigQuery, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

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 .