Working with BigQuery in Google Cloud Shell


Joseph Lowery
Google Cloud Training Architect II in Content
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.
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
- On the lab instructions page, right-click the Open GPC Console button.
- 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.)
- On the Google sign-in page, enter the unique username you were provided on the lab instructions page. Click Next.
- Enter the unique password you were provided on the lab instructions page. Click Next.
- On the Welcome to your new account page, click Accept.
- In the Welcome L.A.! menu, check the box under Terms of service.
- Choose your country of residence, then click AGREE AND CONTINUE.
Activate Cloud Shell
- Click the Activate Cloud Shell icon at the top of the console page.
- Click START CLOUD SHELL.
Retrieve the Data Files
- Run the following command:
gsutil cp gs://la-gcp-labs-resources/essentials/MetObjects_BQ_Lab.csv .
Create a BigQuery Dataset
- Create a BigQuery dataset with the following command:
bq mk metobjects
- List the current datasets.
bq ls
Load the Data
- 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
- View the dataset.
bq ls metobjects
bq show metobjects.linkedObjects
Query the Dataset
- Execute the following SQL query:
bq query "SELECT year,title,artist FROM metobjects.linkedObjects WHERE year > 2000 ORDER BY year DESC LIMIT 15"
- Execute a second SQL query:
bq query "SELECT title,link FROM metobjects.linkedObjects WHERE year > 2000 ORDER BY year DESC LIMIT 15"
- Test the available links.
Conclusion
Congratulations, you've successfully completed this hands-on lab!