예약 가져오기

지정된 BigQuery 예약을 가져옵니다. 이를 사용하여 슬롯 용량, 유휴 슬롯 무시 여부 등 예약의 세부정보를 확인할 수 있습니다.

코드 샘플

Node.js

이 샘플을 사용해 보기 전에 BigQuery 빠른 시작: 클라이언트 라이브러리 사용Node.js 설정 안내를 따르세요. 자세한 내용은 BigQuery Node.js API 참고 문서를 확인하세요.

BigQuery에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 클라이언트 라이브러리의 인증 설정을 참조하세요.

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

const client = new ReservationServiceClient();

/**
 * Returns information about the reservation.
 * A reservation provides computational resource guarantees, in the form of
 * slots, to users. A slot is a unit of computational power in BigQuery.
 *
 * @param {string} projectId Google Cloud Project ID, for example 'example-project-id'.
 * @param {string} location The geographic location where the reservation resides, for example 'us-central1'.
 * @param {string} reservationId The ID of the reservation to retrieve, for example 'example-reservation'.
 */
async function getReservation(
  projectId,
  location = 'us-central1',
  reservationId = 'example-reservation',
) {
  const request = {
    name: client.reservationPath(projectId, location, reservationId),
  };

  try {
    const [reservation] = await client.getReservation(request);
    console.log(`Got reservation: ${reservation.name}`);
    console.log(`  Slot capacity: ${reservation.slotCapacity}`);
    console.log(`  Ignore idle slots: ${reservation.ignoreIdleSlots}`);
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.log(
        `Reservation '${reservationId}' not found in project '${projectId}' location '${location}'.`,
      );
    } else {
      console.error('Error getting reservation:', err);
    }
  }
}

Python

이 샘플을 사용해 보기 전에 BigQuery 빠른 시작: 클라이언트 라이브러리 사용Python 설정 안내를 따르세요. 자세한 내용은 BigQuery Python API 참고 문서를 확인하세요.

BigQuery에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 클라이언트 라이브러리의 인증 설정을 참조하세요.

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

client = bigquery_reservation_v1.ReservationServiceClient()


def get_reservation(project_id: str, location: str, reservation_id: str):
    """Gets information about a reservation.

    A reservation is a mechanism used to guarantee slots to users.

    Args:
        project_id: The Google Cloud project ID.
        location: The geographic location of the reservation, for example, "us-central1".
        reservation_id: The ID of the reservation to retrieve.
    """

    name = client.reservation_path(project_id, location, reservation_id)

    try:
        reservation = client.get_reservation(name=name)
        print(f"Retrieved reservation: {reservation.name}")
        print(f"\tSlot capacity: {reservation.slot_capacity}")
        print(f"\tIgnore idle slots: {reservation.ignore_idle_slots}")
    except exceptions.NotFound:
        print(f"Reservation '{reservation_id}' not found.")

다음 단계

다른 Google Cloud 제품의 코드 샘플을 검색하고 필터링하려면 Google Cloud 샘플 브라우저를 참조하세요.