arrow_back

Creating and Populating a Bigtable Instance

Acceder Unirse
Test and share your knowledge with our community!
done
Get access to over 700 hands-on labs, skill badges, and courses

Creating and Populating a Bigtable Instance

Lab 1 hora 30 minutos universal_currency_alt 1 crédito show_chart Introductorio
Test and share your knowledge with our community!
done
Get access to over 700 hands-on labs, skill badges, and courses

GSP1054

Google Cloud self-paced labs logo

Overview

Bigtable is Google's fully managed, scalable NoSQL database service. Bigtable is ideal for storing large amounts of data in a key-value store and for use cases such as personalization, ad tech, financial tech, digital media, and Internet of Things (IoT). Bigtable supports high read and write throughput at low latency for fast access to large amounts of data for processing and analytics.

For personalization use cases, Bigtable can handle both high writes to store users' interactions with online products and high reads to provide these interactions to models that produce personalized recommendations.

In this lab, you use the Google Cloud Console to create a Bigtable instance with a table to store user interactions with products. Then, you use a Dataflow template to populate the table from pre-generated data files on Cloud Storage. After the Dataflow job has finished, you verify that the table has been successfully populated with data and then complete the lab by deleting the Bigtable data.

What you'll do

In this lab, you learn how to create a Bigtable instance and load data from Cloud Storage without writing any code.

  • Create a Bigtable instance and a Bigtable table with column families.
  • Use a Dataflow template to load SequenceFile files from Cloud Storage into Bigtable.
  • Verify the data loaded into Bigtable.
  • Delete the Bigtable table and instance.

Prerequisites

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.

    {{{user_0.username | "Username"}}}

    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.

    {{{user_0.password | "Password"}}}

    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

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 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, . The output contains a line that declares the Project_ID for this session:

Your Cloud Platform project in this session is set to {{{project_0.project_id | "PROJECT_ID"}}}

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

  1. (Optional) You can list the active account name with this command:
gcloud auth list
  1. Click Authorize.

Output:

ACTIVE: * ACCOUNT: {{{user_0.username | "ACCOUNT"}}} To set the active account, run: $ gcloud config set account `ACCOUNT`
  1. (Optional) You can list the project ID with this command:
gcloud config list project

Output:

[core] project = {{{project_0.project_id | "PROJECT_ID"}}} Note: For full documentation of gcloud, in Google Cloud, refer to the gcloud CLI overview guide.

Dataflow API

Ensure that the Dataflow API is successfully enabled

To ensure access to the necessary API, restart the connection to the Dataflow API.

  1. In the Google Cloud Console, enter Dataflow API in the top search bar.

  2. Click on the result for Dataflow API.

  3. Click Manage.

  4. Click Disable API.

    If you are asked to confirm, click Disable.

  5. Click Enable.

Click Check my progress to verify the objective. Dataflow API

Task 1. Create a Bigtable instance

To create a new table in Bigtable, you first need to create a Bigtable instance to store your table.

  1. In the Google Cloud Console, on the Navigation menu (nav-menu), under Databases, click Bigtable.

  2. Click Create instance.

  3. Enter the required information to create a Bigtable instance:

Property Value
Instance name Personalized Sales
Instance ID Leave the default value
Storage Type SSD
Cluster ID Leave the default value
Region
Zone
Node scaling mode Manual allocation
Quantity Leave the default value



  1. Click Create.

Click Check my progress to verify the objective. Create a Bigtable instance.

Task 2. Create a new Bigtable table

In Bigtable, each row in a table has a unique identifier called a row key, and columns in a table are grouped by column family to organize related columns. In this task, you create a new Bigtable table with appropriate row keys and column families for user interactions.

First, you create a table named UserSessions to store user online interactions with various products and confirmed sales, using the user ID combined with the timestamp as the row key. Then you create two column families called Interactions and Sales to help organize the related columns.

  1. From the list of Bigtable instances, click on the instance ID named personalized-sales.

  2. In the navigation menu, under Instance, click Tables.

  3. Click Create table.

  4. For Table ID, type UserSessions

  5. Click Add column family.

  6. For Column family name, type Interactions

Leave the default value for garbage collection policy.

  1. Click Done.

  2. Repeat steps 5 through 7 to create another column family named Sales.

  3. Click Create.

Click Check my progress to verify the objective. Create a new Bigtable table.

Task 3. Load data files from Cloud Storage using a Dataflow template

In this task, you run a Dataflow job to load data from Cloud Storage to Bigtable. In order to run the Dataflow job successfully, you first have to create a Cloud Storage bucket for Dataflow to write temporary files as needed. Then you can successfully create and run a new Dataflow job from a template.

Create a Cloud Storage bucket

  1. In the Google Cloud Console, on the Navigation menu (nav-menu), click Cloud overview > Dashboard.

  2. Under Project info, copy the value for Project ID (such as ).

    You will use your Qwiklabs Project ID, which is already globally unique, as the Cloud Storage bucket name.

  3. In the Google Cloud Console, on the Navigation menu (nav-menu), click Cloud Storage > Buckets.

  4. Click Create Bucket.

  5. Enter the required information to create a Cloud Storage bucket, replacing project-id with the project ID you copied in step 2.

Property Value
Name project-id
Location type Multi-region
Location us (multiple regions in United States)



Leave the default values for the remaining parameters.

  1. Click Create.

  2. If prompted Public access will be prevented, click Confirm.

Create a Dataflow job using a template

  1. In the Google Cloud Console, on the Navigation menu (nav-menu), under Analytics, click Dataflow > Jobs.

  2. Click Create job from template.

  3. Enter the required information to create a Dataflow job from a template, replacing project-id with the project ID you previously copied.

Property Value
Job name import-usersessions
Regional endpoint
Dataflow template SequenceFile Files on Cloud Storage to Cloud Bigtable
Project ID project-id
Instance ID personalized-sales
Table ID UserSessions
Source path pattern gs://cloud-training/OCBL377/retail-interactions-sales-00000-of-00001
Temporary location gs://project-id/temp



Leave the default values for the remaining parameters.

  1. Click Run Job.

  2. On the Job Graph page, under Job steps view, select Graph view.

The Graph view displays a graph of how the job progresses to complete the following steps:

  • Read the SequenceFiles on Cloud Storage.
  • Mutate the data for loading into Bigtable.
  • Write the data to Bigtable.
  1. To see a table view of the same steps, select Table view.

When the job has successfully completed, a green check mark for a Succeeded status is displayed next to each task in the Job Graph. This job will take approximately 3 to 5 minutes to run successfully.

Click Check my progress to verify the objective. Load data files from Cloud Storage using a Dataflow template.

Task 4. Verify data loaded into Bigtable

After your Dataflow job has successfully completed, you can use cbt (Cloud Bigtable command-line tool) commands to connect to your Bigtable instance and verify that the table has been populated with data.

Configure the Bigtable CLI

To connect to Bigtable using cbt CLI commands, you first need to update the .cbtrc configuration file with your project ID and your Bigtable instance ID using Cloud Shell.

For a review of how to access Cloud Shell, click Setup and Requirements on the right-side menu of this page.

  1. To modify the .cbtrc file with the project ID and instance ID, run the following commands in Cloud Shell:
echo project = `gcloud config get-value project` \ >> ~/.cbtrc echo instance = personalized-sales \ >> ~/.cbtrc
  1. To verify that you successfully modified the .cbtrc file, run the following command:
cat ~/.cbtrc

The output should resemble the following:

project = <project-id> instance = personalized-sales

Query data in the table

After you configure the .cbtrc configuration file in Cloud Shell, you can run a simple cbt CLI command to query the first ten records of the table.

  • To see the data for the first ten rows of the table, run the following command:
cbt read UserSessions \ count=10

The output is structured as follows:

---------------------------------------------- ROW KEY COLUMN_FAMILY:COLUMN_QUALIFIER @ TIMESTAMP VALUE

The output values will resemble the following:

---------------------------------------------- blue1#1638940844409 Interactions:blue_blouse @ 2022/06/07-18:34:28.858000 "purchased" Interactions:blue_jacket @ 2022/06/07-18:34:28.858000 "viewed details" Interactions:blue_shoes @ 2022/06/07-18:34:28.858000 "viewed details" Interactions:green_skirt @ 2022/06/07-18:34:28.858000 "seen" Interactions:orange_dress @ 2022/06/07-18:34:28.858000 "seen" Interactions:purple_dress @ 2022/06/07-18:34:28.858000 "seen" Interactions:purple_skirt @ 2022/06/07-18:34:28.858000 "seen" Interactions:user_id @ 2022/06/07-18:34:28.858000 "blue1" Interactions:yellow_blouse @ 2022/06/07-18:34:28.858000 "seen" Sales:sale @ 2022/06/07-18:34:28.858000 "blue_blouse"

Task 5. Delete a Bigtable table and instance

  1. In the Google Cloud Console, on the Navigation menu (nav-menu), under Databases, click Bigtable.

  2. From the list of Bigtable Instances, click on the Instance ID named personalized-sales.

  3. In the navigation menu, under Instance, click Tables.

  4. Click on the table named UserSessions.

  5. Click Delete table.

  6. In the confirmation dialog, type UserSessions

  7. Click Delete.

  8. In the navigation menu, under Instance, click Overview.

  9. Click Delete instance.

  10. In the confirmation dialog, type personalized-sales

  11. Click Delete.

Click Check my progress to verify the objective. Delete a Bigtable table and instance.

Congratulations!

In this lab, you used Bigtable to create a new instance and table, loaded data into the table using a Dataflow template, and confirmed that the data was successfully loaded by running simple cbt CLI commands. Then, you completed the lab by deleting the Bigtable table and instance.

Next steps / Learn more

Google Cloud training and certification

...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 30, 2024

Lab Last Tested February 17, 2023

Copyright 2024 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.