Retrieves a specific reservation group resource from the BigQuery Reservation API by its name.

## Code sample

### Java


Before trying this sample, follow the Java setup instructions in the
[BigQuery quickstart using
client libraries](https://docs.cloud.google.com/bigquery/docs/quickstarts/quickstart-client-libraries).


For more information, see the
[BigQuery Java API
reference documentation](https://docs.cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/overview).


To authenticate to BigQuery, set up Application Default Credentials.
For more information, see

[Set up authentication for client libraries](https://docs.cloud.google.com/bigquery/docs/authentication#client-libs).

    import com.google.api.gax.rpc.https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.ApiException.html;
    import com.google.api.gax.rpc.https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.NotFoundException.html;
    import com.google.cloud.bigquery.reservation.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-bigqueryreservation/latest/com.google.cloud.bigquery.reservation.v1.GetReservationGroupRequest.html;
    import com.google.cloud.bigquery.reservation.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-bigqueryreservation/latest/com.google.cloud.bigquery.reservation.v1.ReservationGroup.html;
    import com.google.cloud.bigquery.reservation.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-bigqueryreservation/latest/com.google.cloud.bigquery.reservation.v1.ReservationGroupName.html;
    import com.google.cloud.bigquery.reservation.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-bigqueryreservation/latest/com.google.cloud.bigquery.reservation.v1.ReservationServiceClient.html;
    import java.io.IOException;

    public class GetReservationGroup {

      /**
       * Retrieves information about a specified BigQuery reservation group. A reservation group is a
       * container for reservations.
       *
       * @param projectId The Google Cloud project ID (for example, "example-project-id").
       * @param location The geographic location of the reservation group (for example, "us-central1").
       * @param reservationGroupId The ID of the reservation group to retrieve (for example,
       *     "example-reservation-group").
       */
      public static void getReservationGroup(
          String projectId, String location, String reservationGroupId) {
        https://docs.cloud.google.com/java/docs/reference/google-cloud-bigqueryreservation/latest/com.google.cloud.bigquery.reservation.v1.ReservationGroupName.html name =
            https://docs.cloud.google.com/java/docs/reference/google-cloud-bigqueryreservation/latest/com.google.cloud.bigquery.reservation.v1.ReservationGroupName.html.of(projectId, location, reservationGroupId);

        https://docs.cloud.google.com/java/docs/reference/google-cloud-bigqueryreservation/latest/com.google.cloud.bigquery.reservation.v1.GetReservationGroupRequest.html request =
            https://docs.cloud.google.com/java/docs/reference/google-cloud-bigqueryreservation/latest/com.google.cloud.bigquery.reservation.v1.GetReservationGroupRequest.html.newBuilder().setName(name.https://docs.cloud.google.com/java/docs/reference/google-cloud-bigqueryreservation/latest/com.google.cloud.bigquery.reservation.v1.ReservationGroupName.html#com_google_cloud_bigquery_reservation_v1_ReservationGroupName_toString__()).build();

        try (https://docs.cloud.google.com/java/docs/reference/google-cloud-bigqueryreservation/latest/com.google.cloud.bigquery.reservation.v1.ReservationServiceClient.html client = https://docs.cloud.google.com/java/docs/reference/google-cloud-bigqueryreservation/latest/com.google.cloud.bigquery.reservation.v1.ReservationServiceClient.html.create()) {
          https://docs.cloud.google.com/java/docs/reference/google-cloud-bigqueryreservation/latest/com.google.cloud.bigquery.reservation.v1.ReservationGroup.html reservationGroup = client.getReservationGroup(request);
          System.out.printf("Retrieved reservation group: %s%n", reservationGroup.https://docs.cloud.google.com/java/docs/reference/google-cloud-bigqueryreservation/latest/com.google.cloud.bigquery.reservation.v1.ReservationGroup.html#com_google_cloud_bigquery_reservation_v1_ReservationGroup_getName__());
        } catch (https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.NotFoundException.html err) {
          System.err.printf(
              "error: reservation group '%s' not found in location '%s' for project '%s': %s%n",
              reservationGroupId, location, projectId, err.https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.ErrorDetails.html#com_google_api_gax_rpc_ErrorDetails__T_getMessage_java_lang_Class_T__());
        } catch (https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.ApiException.html | IOException err) {
          System.err.printf(
              "error: failed to get reservation group '%s' in location '%s' for project '%s': %s%n",
              reservationGroupId, location, projectId, err.https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.ErrorDetails.html#com_google_api_gax_rpc_ErrorDetails__T_getMessage_java_lang_Class_T__());
        }
      }

### Node.js


Before trying this sample, follow the Node.js setup instructions in the
[BigQuery quickstart using
client libraries](https://docs.cloud.google.com/bigquery/docs/quickstarts/quickstart-client-libraries).


For more information, see the
[BigQuery Node.js API
reference documentation](https://googleapis.dev/nodejs/bigquery/latest/index.html).


To authenticate to BigQuery, set up Application Default Credentials.
For more information, see

[Set up authentication for client libraries](https://docs.cloud.google.com/bigquery/docs/authentication#client-libs).

    const {ReservationServiceClient} =
      require('https://docs.cloud.google.com/nodejs/docs/reference/bigquery-reservation/latest/overview.html').v1;
    const {status} = require('@grpc/grpc-js');

    const client = new https://docs.cloud.google.com/nodejs/docs/reference/bigquery-reservation/latest/overview.html();

    /**
     * Gets the specified reservation group.
     *
     * A reservation group is a container for reservations.
     *
     * @param projectId Google Cloud Project ID, for example 'example-project-id'.
     * @param location Google Cloud Location, for example 'us-central1'.
     * @param reservationGroupId the ID of the reservation group to get, for example 'example-reservation-group-id'.
     */
    async function getReservationGroup(
      projectId,
      location = 'us-central1',
      reservationGroupId = 'example-group-reservation',
    ) {
      const request = {
        name: client.reservationGroupPath(projectId, location, reservationGroupId),
      };

      try {
        const [reservationGroup] = await client.getReservationGroup(request);
        console.log(`Got reservation group: ${reservationGroup.name}`);
      } catch (err) {
        if (err.code === status.NOT_FOUND) {
          console.log(
            `Reservation group '${reservationGroupId}' not found in project '${projectId}' at location '${location}'.`,
          );
        } else {
          console.error(
            `Error getting reservation group '${reservationGroupId}':`,
            err,
          );
        }
      }
    }

### Python


Before trying this sample, follow the Python setup instructions in the
[BigQuery quickstart using
client libraries](https://docs.cloud.google.com/bigquery/docs/quickstarts/quickstart-client-libraries).


For more information, see the
[BigQuery Python API
reference documentation](https://docs.cloud.google.com/python/docs/reference/bigquery/latest).


To authenticate to BigQuery, set up Application Default Credentials.
For more information, see

[Set up authentication for client libraries](https://docs.cloud.google.com/bigquery/docs/authentication#client-libs).

    from google.api_core import exceptions
    from google.cloud import https://docs.cloud.google.com/python/docs/reference/bigqueryreservation/latest


    client = https://docs.cloud.google.com/python/docs/reference/bigqueryreservation/latest.https://docs.cloud.google.com/python/docs/reference/bigqueryreservation/latest/google.cloud.bigquery_reservation_v1.services.reservation_service.ReservationServiceClient.html()


    def get_reservation_group(project_id: str, location: str, reservation_group_id: str):
        """Gets information about a reservation group.

        A reservation group is a container for reservations.

        Args:
            project_id: The Google Cloud project ID.
            location: The geographic location of the reservation group, for example, us-central1.
            reservation_group_id: The ID of the reservation group to retrieve.
        """
        name = client.https://docs.cloud.google.com/python/docs/reference/bigqueryreservation/latest/google.cloud.bigquery_reservation_v1.services.reservation_service.ReservationServiceClient.html#google_cloud_bigquery_reservation_v1_services_reservation_service_ReservationServiceClient_reservation_group_path(project_id, location, reservation_group_id)

        try:
            reservation_group = client.https://docs.cloud.google.com/python/docs/reference/bigqueryreservation/latest/google.cloud.bigquery_reservation_v1.services.reservation_service.ReservationServiceClient.html#google_cloud_bigquery_reservation_v1_services_reservation_service_ReservationServiceClient_get_reservation_group(name=name)
            print(f"Retrieved reservation group: {reservation_group.name}")
        except exceptions.NotFound:
            print(f"Reservation group '{name}' not found.")

## What's next


To search and filter code samples for other Google Cloud products, see the
[Google Cloud sample browser](https://docs.cloud.google.com/docs/samples?product=bigquery).