You are tasked with exploring Cloud Bigtable as a potential database for storing location data updates for a fleet of public transport vehicles. For now, you need to interact with Bigtable to help you develop a row-key design. In this lab, we will create a Cloud Bigtable instance and then write and query data with the HBase shell.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Create a Cloud Bigtable Instance
For our Cloud Bigtable instance:
- Create a Bigtable instance with the name
vehicle-locations
. - Make sure HDD is selected for our instance.
- For Region, choose us-east1 and set the Zone as
Any
. - Make sure the number of nodes listed is
1
.
- Create a Bigtable instance with the name
- Connect to Bigtable with HBase
To connect to Bigtable with HBase:
- From the top of the GCP dashboard, click the Activate Cloud Shell button (the square button with
>_
in it). - Using
sudo
, update the cloud shell and install the Java 8 runtime for HBase. - Clone the Bigtable examples repo:
https://github.com/GoogleCloudPlatform/cloud-bigtable-examples.git
- Change to the
cloud-bigtable-examples/quickstart
directory. - Run the
quickstart.sh
script to set up a connection. Don’t worry about any errors or warnings, as the script should pick up your project’s Bigtable instance and drop you into a connected HBase shell.
Don’t disconnect! Stay in the HBase shell for the next objective.
- From the top of the GCP dashboard, click the Activate Cloud Shell button (the square button with
- Create a Table and Write and Query Its Data with HBase
We need to create a table using the provided information and then query that data with HBase:
- Create a table named
vehicles
with column groups calledloc
anddet
. - Enter the following details into the table for our two vehicles, placing the Lat and Long data in the
loc
column group, and the Company and Route data in thedet
column group:
Row Key Lat Long Company Route M117-223 40.781212 -73.961942 NYMT 86 M117-391 40.780664 -73.958357 NYMT 88 - Use
get
to pull a single row using a row key. - Scan the entire table.
- Find all vehicles assigned to Route 88 using a
ValueFilter
with aregexstring
.
Note: This is an example of an extremely inefficient way to search the database. The entire table needs to be read to find matching rows. - Perform a scan for the second vehicle using the
ROWPREFIXFILTER
filter and the first 6 characters from the Row Key column.
- Create a table named