예약의 모든 할당 나열

지정된 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 reservationServiceClient = new ReservationServiceClient();

/**
 * Lists assignments.
 * An assignment lets a project, folder, or organization use slots from a
 * specified reservation. By using a wildcard `-` for the reservation ID,
 * this sample lists all assignments for a given project and location.
 *
 * @param {string} projectId The ID of the project. Example: 'example-project-id'
 * @param {string} location The location of the reservation. Example: 'us-central1'
 */
async function listAssignments(projectId, location = 'us-central1') {
  const request = {
    parent: `projects/${projectId}/locations/${location}/reservations/-`,
  };

  try {
    const iterable = reservationServiceClient.listAssignmentsAsync(request);
    console.log(`Assignments in parent "${request.parent}":`);

    let found = false;
    for await (const assignment of iterable) {
      found = true;
      console.log(`- ${assignment.name}`);
      console.log(`  - Assignee: ${assignment.assignee}`);
      console.log(`  - Job Type: ${assignment.jobType}`);
    }

    if (!found) {
      console.log('  No assignments found.');
    }
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.log(`Parent resource not found: ${request.parent}`);
    } else {
      console.error('Error listing assignments:', err);
    }
  }
}

Python

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

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

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


def list_assignments(
    project_id: str,
    location: str,
    reservation_id: str,
):
    """Lists all assignments for a reservation.

    This sample shows how to list all assignments in a given reservation.
    To list all assignments in a given location, across all reservations,
    use a wildcard `-` for the reservation ID.

    Args:
        project_id: The Google Cloud project ID.
        location: The geographic location of the assignments , for example, 'us-central1'.
        reservation_id: The ID of the reservation to list assignments for, or "-"
            to list all assignments for the project and location.
    """
    client = bigquery_reservation_v1.ReservationServiceClient()
    parent = client.reservation_path(project_id, location, reservation_id)

    try:
        print(f"Listing assignments for parent: '{parent}'")
        assignment_list = client.list_assignments(parent=parent)

        found_assignments = False
        for assignment in assignment_list:
            found_assignments = True
            print(f"  Got assignment: {assignment.name}")

        if not found_assignments:
            print("No assignments found.")

    except exceptions.NotFound:
        print(f"Parent resource '{parent}' not found.")

다음 단계

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