BigQuery 예약 삭제

BigQuery Reservation API에서 예약을 삭제합니다. 예약에 할당이 없어야 합니다.

코드 샘플

Node.js

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

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

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

const client = new ReservationServiceClient();

/**
 * Deletes a reservation.
 * A reservation provides computational resource guarantees, in the form of slots, to users.
 * @param {string} projectId The Google Cloud 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 delete, for example 'example-reservation'.
 */
async function deleteReservation(
  projectId,
  location = 'us-central1',
  reservationId = 'example-reservation',
) {
  // Construct the fully-qualified path for the reservation.
  const name = client.reservationPath(projectId, location, reservationId);

  const request = {
    name,
  };

  try {
    await client.deleteReservation(request);
    console.log(`Deleted reservation: ${reservationId}`);
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.log(
        `Reservation ${reservationId} not found in project ${projectId} location ${location}.`,
      );
    } else {
      console.error(`Error deleting reservation ${reservationId}:`, err);
    }
  }
}

Python

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

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

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

client = bigquery_reservation_v1.ReservationServiceClient()


def delete_reservation(project_id: str, location: str, reservation_id: str):
    """Deletes a reservation.

    A reservation can only be deleted if it has no assignments.

    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 delete.
    """
    name = client.reservation_path(project_id, location, reservation_id)

    try:
        client.delete_reservation(name=name)
        print(f"Deleted reservation: {name}")
    except NotFound:
        print(f"Reservation '{name}' not found.")

다음 단계

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