Ottenere una prenotazione BI

Recupera i dettagli di una prenotazione BI specificata dall'API BigQuery Reservation.

Esempio di codice

Node.js

Prima di provare questo esempio, segui le istruzioni di configurazione di Node.js nella guida rapida di BigQuery per l'utilizzo delle librerie client. Per saperne di più, consulta la documentazione di riferimento dell'API BigQuery Node.js.

Per eseguire l'autenticazione in BigQuery, configura le Credenziali predefinite dell'applicazione. Per saperne di più, vedi Configurare l'autenticazione per le librerie client.

const {ReservationServiceClient} =
  require('@google-cloud/bigquery-reservation').v1;
const {status} = require('@grpc/grpc-js');

const client = new ReservationServiceClient();

/**
 * Retrieves a BI reservation.
 * A BI reservation is a singleton resource in a location.
 * @param {string} projectId Google Cloud project ID, for example 'example-project-id'.
 * @param {string} location Google Cloud location, for example 'US'.
 */
async function getBiReservation(projectId, location = 'US') {
  const name = client.biReservationPath(projectId, location);
  const request = {
    name,
  };

  try {
    const [reservation] = await client.getBiReservation(request);
    console.log(`Got BI reservation: ${reservation.name}`);
    console.log(`  Size: ${reservation.size} bytes`);
    if (reservation.updateTime) {
      const updateTime = new Date(
        reservation.updateTime.seconds * 1000 +
          reservation.updateTime.nanos / 1000000,
      );
      console.log(`  Last updated: ${updateTime.toISOString()}`);
    }
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.log(
        `BI reservation not found for project ${projectId} in location ${location}.`,
      );
    } else {
      console.error('Error getting BI reservation:', err);
    }
  }
}

Python

Prima di provare questo esempio, segui le istruzioni di configurazione di Python nella guida rapida di BigQuery per l'utilizzo delle librerie client. Per saperne di più, consulta la documentazione di riferimento dell'API BigQuery Python.

Per eseguire l'autenticazione in BigQuery, configura le Credenziali predefinite dell'applicazione. Per saperne di più, vedi Configurare l'autenticazione per le librerie client.

from google.api_core.exceptions import NotFound
from google.cloud import bigquery_reservation_v1


def get_bi_reservation(project_id: str, location: str):
    """Gets a BI reservation.

    A BI reservation is a singleton resource. It is not created explicitly, but
    can be updated to enable BI Engine.

    Args:
        project_id: The Google Cloud project ID.
        location: The geographic location of the BI reservation , for example, us-central1.
    """
    client = bigquery_reservation_v1.ReservationServiceClient()
    name = client.bi_reservation_path(project_id, location)

    try:
        reservation = client.get_bi_reservation(name=name)
        print(f"Got BI reservation: {reservation.name}")
        print(f"\tSize: {reservation.size} bytes")
        print(f"\tUpdated at: {reservation.update_time}")
    except NotFound:
        print(
            f"BI reservation not found for project '{project_id}' in location '{location}'."
        )

Passaggi successivi

Per cercare e filtrare gli esempi di codice per altri prodotti Google Cloud , consulta il browser degli esempi diGoogle Cloud .