BI 예약 가져오기

BigQuery Reservation API에서 지정된 BI 예약의 세부정보를 가져옵니다.

코드 샘플

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();

/**
 * 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

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

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

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}'."
        )

다음 단계

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