
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Run a query (dataset: samples, table: shakespeare, substring: raisin)
/ 10
Run a query (dataset: samples, table: shakespeare, substring: huzzah)
/ 10
Create a new dataset (name: babynames)
/ 20
Load the data into a new table
/ 20
Run queries against your dataset table
/ 20
Remove the babynames dataset
/ 20
Storing and querying massive datasets can be time consuming and expensive without the right hardware and infrastructure. BigQuery is a serverless, highly scalable cloud 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 Google Cloud 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 by using the Console,Web UI or a command-line tool using a variety of client libraries such as Java, .NET, or Python. There are also a variety of solution providers that you can use to interact with BigQuery.
This hands-on lab shows you how to use bq
, the python-based command line tool for BigQuery, to query public tables and load sample data into BigQuery.
BigQuery offers a number of sample tables that you can run queries against. In this lab, you'll run queries against the shakespeare
table, which contains an entry for every word in every play.
In this command you're doing the following:
bq
to invoke the BigQuery command line toolshow
is the actionproject:public dataset.table
in BigQuery that you want to see.Output:
When you include a command name with the help commands, you get information about that specific command.
bq help
retrieves information about the query
command:bq
uses, just bq help
.Now you'll run a query to see how many times the substring raisin appears in Shakespeare's works.
To run a query, run the command bq query "[SQL_STATEMENT]"
:
Escape any quotation marks inside the [SQL_STATEMENT] with a \ mark, or
Use a different quotation mark type than the surrounding marks ("versus").
Run the following standard SQL query in Cloud terminal to count the number of times that the substring raisin appears in all of Shakespeare's works:
In this command:
--use_legacy_sql=false
makes standard SQL the default query syntax.Output:
The table demonstrates that although the actual word raisin doesn't appear, the letters appear in order in several of Shakespeare's works.
Click Check my progress to verify the objective.
If you search for a word that isn't in Shakespeare's works, no results are returned.
Click Check my progress to verify the objective.
Now create your own table. Every table is stored inside a dataset. A dataset is a group of resources, such as tables and views.
bq ls
command to list any existing datasets in your project:You will be brought back to the command line since there aren't any datasets in your project yet.
bq ls
and the bigquery-public-data
Project ID to list the datasets in that specific project, followed by a colon (:):Output:
Next, create a dataset. A dataset name can be up to 1,024 characters long, and consist of A-Z, a-z, 0-9, and the underscore, but it cannot start with a number or underscore, or have spaces.
bq mk
command to create a new dataset named babynames
in your project:Sample output:
Click Check my progress to verify the objective.
bq ls
to confirm that the dataset now appears as part of your project:Sample output:
Before you can build the table, you need to add the dataset to your project. The custom data file you'll use contains approximately 7 MB of data about popular baby names, provided by the US Social Security Administration.
See the name of the file added to your project.
The bq load
command creates or updates a table and loads data in a single step.
You will use the bq load
command to load your source file into a new table called names2010 in the babynames dataset you just created. By default, this runs synchronously, and will take a few seconds to complete.
The bq load
arguments you'll be running are:
Sample output:
Click Check my progress to verify the objective.
bq ls
and babynames
to confirm that the table now appears in your dataset:Output:
bq show
and your dataset.table
to see the schema:Output:
By default, when you load data, BigQuery expects UTF-8 encoded data. If you have data that is in ISO-8859-1 (or Latin-1) encoding and are having problems with your loaded data, you can tell BigQuery to treat your data as Latin-1 explicitly, using the -E flag. Learn more about Character Encodings from the Introduction to loading data guide.
Now you're ready to query the data and return some interesting results.
Output:
Note: The minimum count is 5 because the source data omits names with fewer than 5 occurrences.
Output:
Click Check my progress to verify the objective.
bq rm
command to remove the babynames
dataset with the -r
flag to delete all tables in the dataset:Y
.Click Check my progress to verify the objective.
Now you can use the command line to query public tables and load sample data into BigQuery.
Learn more about the BigQuery and bq
command-line tool:
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated May 26, 2025
Lab Last Tested May 26, 2025
Copyright 2025 Google LLC. All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one