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 サンプル ブラウザをご覧ください。