# BigQuery: Qwik Start - Console - GSP072

## **Overview**

Storing and querying massive datasets can be time consuming and expensive without the right hardware and infrastructure. BigQuery is an [enterprise data warehouse](https://cloud.google.com/solutions/bigquery-data-warehouse) that solves this problem by enabling super-fast SQL queries using the processing power of Google's infrastructure. Simply move your data into BigQuery and let us handle the hard work. You can control access to both the project and your data based on your business needs, such as giving others the ability to view or query your data.

You can access BigQuery in the [Console](https://cloud.google.com/bigquery/docs/quickstarts/quickstart-web-ui), the [command-line tool](https://cloud.google.com/bigquery/docs/cli_tool), or by making calls to the [BigQuery REST API](https://cloud.google.com/bigquery/docs/reference/v2) using a variety of [client libraries](https://cloud.google.com/bigquery/docs/reference/libraries) such as Java, .NET, or Python. There are also a variety of [third-party tools](https://cloud.google.com/bigquery/third-party-tools) that you can use to interact with BigQuery, such as visualizing the data or loading the data.

This hands-on lab shows you how to query public tables and load sample data into BigQuery.

### What you'll do

* Query a public dataset
    
* Create a new dataset
    
* Load data into a new table
    
* Query a custom table
    

## **Setup and requirements**

### Before you click the Start Lab button

Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click **Start Lab**, shows how long Google Cloud resources will be made available to you.

This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.

To complete this lab, you need:

* Access to a standard internet browser (Chrome browser recommended).
    

**Note:** Use an Incognito or private browser window to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.

* Time to complete the lab---remember, once you start, you cannot pause a lab.
    

**Note:** If you already have your own personal Google Cloud account or project, do not use it for this lab to avoid extra charges to your account.

### How to start your lab and sign in to the Google Cloud console

1. Click the **Start Lab** button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the **Lab Details** panel with the following:
    
    * The **Open Google Cloud console** button
        
    * Time remaining
        
    * The temporary credentials that you must use for this lab
        
    * Other information, if needed, to step through this lab
        
2. Click **Open Google Cloud console** (or right-click and select **Open Link in Incognito Window** if you are running the Chrome browser).
    
    The lab spins up resources, and then opens another tab that shows the **Sign in** page.
    
    ***Tip:*** Arrange the tabs in separate windows, side-by-side.
    
    **Note:** If you see the **Choose an account** dialog, click **Use Another Account**.
    
3. If necessary, copy the **Username** below and paste it into the **Sign in** dialog.
    
    ```apache
    student-04-fb743da47708@qwiklabs.net
    ```
    
    You can also find the **Username** in the **Lab Details** panel.
    
4. Click **Next**.
    
5. Copy the **Password** below and paste it into the **Welcome** dialog.
    
    ```apache
    M4eGD9dZRNn4
    ```
    
    You can also find the **Password** in the **Lab Details** panel.
    
6. Click **Next**.
    
    **Important:** You must use the credentials the lab provides you. Do not use your Google Cloud account credentials.
    
    **Note:** Using your own Google Cloud account for this lab may incur extra charges.
    
7. Click through the subsequent pages:
    
    * Accept the terms and conditions.
        
    * Do not add recovery options or two-factor authentication (because this is a temporary account).
        
    * Do not sign up for free trials.
        

After a few moments, the Google Cloud console opens in this tab.

**Note:** To view a menu with a list of Google Cloud products and services, click the **Navigation menu** at the top-left.

![Navigation menu icon](https://cdn.qwiklabs.com/nUxFb6oRFr435O3t6V7WYJAjeDFcrFb16G9wHWp5BzU%3D align="left")

### Activate Cloud Shell

Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.

1. Click **Activate Cloud Shell**
    
    ![Activate Cloud Shell icon](https://cdn.qwiklabs.com/ep8HmqYGdD%2FkUncAAYpV47OYoHwC8%2Bg0WK%2F8sidHquE%3D align="left")
    
    at the top of the Google Cloud console.
    

When you are connected, you are already authenticated, and the project is set to your **Project\_ID**, `qwiklabs-gcp-03-a14538c79194`. The output contains a line that declares the **Project\_ID** for this session:

```apache
Your Cloud Platform project in this session is set to qwiklabs-gcp-03-a14538c79194
```

`gcloud` is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.

2. (Optional) You can list the active account name with this command:
    

```apache
gcloud auth list
```

3. Click **Authorize**.
    

**Output:**

```apache
ACTIVE: *
ACCOUNT: student-04-fb743da47708@qwiklabs.net

To set the active account, run:
    $ gcloud config set account `ACCOUNT`
```

4. (Optional) You can list the project ID with this command:
    

```apache
gcloud config list project
```

**Output:**

```apache
[core]
project = qwiklabs-gcp-03-a14538c79194
```

**Note:** For full documentation of `gcloud`, in Google Cloud, refer to [the gcloud CLI overview guide](https://cloud.google.com/sdk/gcloud).

## **Task 1. Open BigQuery**

The BigQuery console provides an interface to query tables, including [public datasets](https://cloud.google.com/bigquery/public-data) offered by BigQuery. The query you will run accesses a table from a public dataset that BigQuery provides. It uses standard query language to search the dataset, and limits the results returned to 10.

### Open the BigQuery console

1. In the Google Cloud Console, select **Navigation menu** &gt; **BigQuery**.
    

The **Welcome to BigQuery in the Cloud Console** message box opens. This message box provides a link to the quickstart guide and the release notes.

2. Click **Done**.
    

The BigQuery console opens.

## **Task 2. Query a public dataset**

1. Click **Compose a New Query**. Copy and paste the following query into the BigQuery Query editor:
    

```sql
#standardSQL
SELECT
 weight_pounds, state, year, gestation_weeks
FROM
 `bigquery-public-data.samples.natality`
ORDER BY weight_pounds DESC LIMIT 10;
```

This data sample holds information about US natality (birth rates).

A green or red check displays depending on whether the query is valid or invalid. If the query is valid, the validator also describes the amount of data to be processed after you run the query.

This information helps determine the cost to run a query.

2. Click the **Run** button.
    

Your query results should resemble the following:

![Query results Results table](https://cdn.qwiklabs.com/P2w3ijA1uSEndZInn2By2SQk3hAf%2BUy0%2BTmRI5v3RfQ%3D align="left")

**Test completed task**

Click **Check my progress** to verify your performed task. If you have successfully queried against the public dataset, you'll see an assessment score.

Query a public dataset (dataset: samples, table: natality)

**Check my progress**

**Note:** You can browse the schema of other public datasets in BigQuery by clicking **\+ Add** &gt; **Public Datasets**, then search for "bigquery public data" in the Search Marketplace field.

## **Task 3. Create a new dataset**

To load custom data into a table, you first need to create a BigQuery dataset.

Datasets help control access to tables and views in a project. This lab uses only one table, but you still need a dataset to hold the table.

1. In the **Explorer** pane, near your project id, click on **View actions** (
    
    ![view actions icon](https://cdn.qwiklabs.com/2ufrDePg5inKfodUoT2Kib4oE7II7emYn%2BypCC85FjQ%3D align="left")
    
    ) then click **Create dataset**.
    

![Highlighted Create dataset option in the Explorer section](https://cdn.qwiklabs.com/CHIUP2ZgQqr4U8KEEW0tR3TTU4IVL%2B8qDBt7zdZZigI%3D align="left")

2. Set **Dataset ID** to **babynames**.
    
3. Leave all other fields at their default settings. Click **Create dataset**.
    

Now you have a dataset.

![babynames dataset highlighted in the Explorer section](https://cdn.qwiklabs.com/DFQ6RHgGs5cOpnailVmtuJYKBavovKJcN2WTzNLlzHI%3D align="left")

**Test completed task**

Click **Check my progress** to verify your performed task. If you have successfully created the BigQuery dataset, you'll see an assessment score.

Create a new dataset

**Check my progress**

## **Task 4. Load data into a new table**

Next you create a table inside the **babynames** dataset, then load the data file from your storage bucket into the new table.

The custom data file you'll use contains approximately 7 MB of data about popular baby names, provided by the US Social Security Administration.

1. In the Cloud Console, select **Navigation menu** &gt; **BigQuery** to return to the BigQuery console.
    
2. Navigate to the **babynames** dataset, by clicking **View actions** () near your dataset then click **Create table**.
    
3. In the Create table dialog, set the following fields, leave all others at the default value:
    

| **Field** | **Value** |
| --- | --- |
| Create table from | **Google Cloud Storage** |
| Select file from GCS bucket | `spls/gsp072/baby-names/yob2014.txt` |
| File format | **CSV** |
| Table | `names_2014` |
| Schema &gt; **Edit as text** | Slide on, then add the following in the textbox: `name:string,gender:string,count:integer` |

4. Click the **Create Table** button.
    

When BigQuery is finished creating the table and loading the data, you see the `names_2014` table under the `babynames` dataset.

**Test completed task**

Click **Check my progress** to verify your performed task. If you have successfully loaded data into the dataset table, you'll see an assessment score.

Load data into your table

**Check my progress**

## **Task 5. Preview the table**

Check your table! View the first few rows of the data.

* Click the `names_2014` table in the left panel, then click **Preview**.
    

![Preview tabbed page](https://cdn.qwiklabs.com/Zu8hv37ozVvp0EfyaoVQR3PIpYBMrG64aFUTVMpRZq4%3D align="left")

Your table is ready for queries.

## **Task 6. Query a custom dataset**

Running a query against custom data is identical to the [querying a public dataset](https://cloud.google.com/bigquery/quickstart-web-ui#query_a_public_dataset) that you did earlier, except that now you're querying your own table instead of a public table.

1. In BigQuery, click the **+** (Compose new query) icon at the top.
    
2. Paste or type the following query into the query **Editor**.
    

**Note:** If your table name is something other than **babynames**, update the code with your table name.

```sql
#standardSQL
SELECT
 name, count
FROM
 `babynames.names_2014`
WHERE
 gender = 'M'
ORDER BY count DESC LIMIT 5;
```

3. Click the **Run** button. The query displays the top 5 boys names for the year of data (2014) you loaded into the table.
    

**Test completed task**

Click **Check my progress** to verify your performed task. If you have successfully queried against the custom dataset, you'll see an assessment score.

Query a custom dataset

**Check my progress**

## **Task 7. Test your understanding**

Below is a true/false question to reinforce your understanding of this lab's concepts. Answer it to the best of your abilities.

**BigQuery is a fully-managed enterprise data warehouse that enables super-fast SQL queries.**

* True
    
* False
    

---

## Solution of Lab

%[https://www.youtube.com/watch?v=6yed2O1FAzI] 

```apache
curl -LO raw.githubusercontent.com/ePlus-DEV/storage/refs/heads/main/labs/GSP072/lab.sh
source lab.sh
```

**Script Alternative**

```apache
curl -LO raw.githubusercontent.com/Techcps/Google-Cloud-Skills-Boost/master/BigQuery%3A%20Qwik%20Start%20-%20Console/techcps072.sh
sudo chmod +x techcps072.sh
./techcps072.sh
```
