Skip to main content

Working with BigQuery in Google Cloud Shell

Hands-On Lab

 

Photo of Joseph Lowery

Joseph Lowery

Google Cloud Training Architect II in Content

Length

00:30:00

Difficulty

Beginner

Cloud BigQuery boasts extremely fast processing—terabytes of information in seconds, petabytes in minutes—while remaining straightforward to query via standard SQL. Best of all, BigQuery is accessible through a number of methods, including web console and API. In this hands-on lab, you’ll use another pathway (Google Cloud Shell) to perform a series of BigQuery operations, including creating a dataset, defining a table and its schema, importing data into that table and, finally, running a series of SQL queries on the BigQuery platform.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Working with BigQuery in Google Cloud Shell

Introduction

Cloud BigQuery boasts extremely fast processing—terabytes of information in seconds, petabytes in minutes—while remaining easy to query via standard SQL. Best of all, BigQuery is accessible through a number of methods, including web console and API. In this hands-on lab, you’ll use another pathway (Google Cloud Shell) to perform a series of BigQuery operations, including creating a dataset, defining a table and its schema, importing data into that table and, finally, running a series of SQL queries on the BigQuery platform.

Logging In to the Environment

  1. On the lab instructions page, right-click the Open GPC Console button.
  2. From the dropdown, select the option to open the link in a private browser window. (Note: Different browsers have different names for a private browser window. On Chrome, you'll choose Open Link in Incognito Window. If you're using Firefox, click Open Link in New Private Window. Etc.)
  3. On the Google sign-in page, enter the unique username you were provided on the lab instructions page. Click Next.
  4. Enter the unique password you were provided on the lab instructions page. Click Next.
  5. On the Welcome to your new account page, click Accept.
  6. In the Welcome L.A.! menu, check the box under Terms of service.
  7. Choose your country of residence, then click AGREE AND CONTINUE.

Activate Cloud Shell

  1. Click the Activate Cloud Shell icon at the top of the console page.
  2. Click START CLOUD SHELL.

Retrieve the Data Files

  1. Run the following command:
    gsutil cp gs://la-gcp-labs-resources/essentials/MetObjects_BQ_Lab.csv .

Create a BigQuery Dataset

  1. Create a BigQuery dataset with the following command:
    bq mk metobjects
  2. List the current datasets.
    bq ls

Load the Data

  1. Import the data into the dataset.
    bq load --source_format=CSV --skip_leading_rows=1 metobjects.linkedObjects MetObjects_BQ_Lab.csv title:STRING,artist:STRING,year:INTEGER,link:STRING
  2. View the dataset.
    bq ls metobjects
    bq show metobjects.linkedObjects

Query the Dataset

  1. Execute the following SQL query:
    bq query "SELECT year,title,artist FROM metobjects.linkedObjects WHERE year > 2000 ORDER BY year DESC LIMIT 15"
  2. Execute a second SQL query:
    bq query "SELECT title,link FROM metobjects.linkedObjects WHERE year > 2000 ORDER BY year DESC LIMIT 15"
  3. Test the available links.

Conclusion

Congratulations, you've successfully completed this hands-on lab!