Create an instance and write data with the HBase shell
This page explains how to use the HBase shell to connect to a Cloud Bigtable instance, perform basic administrative tasks, and read and write data in a table.
If you do not want to use the HBase shell, follow the quickstart using
the cbt
tool instead.
This quickstart uses Cloud Shell in the Google Cloud console to run the HBase shell. For improved performance, you can install the HBase shell on your own machine instead.
Before you begin
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Cloud project. Learn how to check if billing is enabled on a project.
-
Enable the Cloud Bigtable and Cloud Bigtable Admin APIs.
Create a Bigtable instance
Open the Create Instance page in the Google Cloud console.
For Instance name, enter
Quickstart instance
.For Instance ID, enter
quickstart-instance
.For Storage type, select SSD.
For Cluster ID, enter
quickstart-instance-c1
.For Region, select us-east1.
For Zone, select us-east1-c.
Click Create to create the instance.
Connect to your instance
-
Open a terminal window in Cloud Shell.
-
To use the HBase shell with the Cloud Bigtable HBase client for Java, you must install a Java 8 runtime environment. Other versions of Java are not supported. Install and set up the Java 8 environment by running the following commands:
sudo apt-get update
sudo apt-get install openjdk-8-jdk-headless
export JAVA_HOME=$(update-alternatives --list java | tail -1 | sed -E 's/\/bin\/java//') -
Clone the repository that contains the HBase shell files, then change to the directory for the HBase shell:
git clone https://github.com/GoogleCloudPlatform/cloud-bigtable-examples.git cd cloud-bigtable-examples/quickstart
Start the HBase shell:
./quickstart.sh
Now you're connected!
Read and write data
Bigtable stores data in tables, which contain rows. Each row is identified by a row key.
Data in a row is organized into column families, which are groups of columns. A column qualifier identifies a single column within a column family.
There can be multiple time-stamped cells at the intersection of a row and column.
Create a table named
my-table
, with one column family namedcf1
:create 'my-table', 'cf1'
The shell displays output similar to the following:
0 row(s) in 1.5210 seconds => Hbase::Table - my-table
List your tables:
list
The shell displays output similar to the following:
TABLE my-table 1 row(s) in 1.3580 seconds => ["my-table"]
Put the values
test-value1
andtest-value2
in the rowr1
, using the column familycf1
and the column qualifierc1
:put 'my-table', 'r1', 'cf1:c1', 'test-value1' put 'my-table', 'r1', 'cf1:c1', 'test-value2'
Use the
scan
command to scan the table and read the latest two versions of the data you added:scan 'my-table', {VERSIONS => 2}
The shell displays output similar to the following:
ROW COLUMN+CELL r1 column=cf1:c1, timestamp=1679495055049, value=test-value1 r1 column=cf1:c1, timestamp=1679494856213, value=test-value2 1 row(s) in 1.2120 seconds
Two timestamped values are stored for the same column in row
r1
.Delete the table
my-table
:disable 'my-table' drop 'my-table'
Type
exit
and press Enter to exit the HBase shell. You will see a series of log messages after you exit, which is normal.
Clean up
To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.
-
Open the list of Bigtable instances in the Google Cloud console.
- Click Quickstart instance.
-
Click Delete instance.
-
Type
quickstart-instance
, then click Delete to delete the instance.
What's next
- Work through a Bigtable codelab.
- Look at code samples.
- See sample source code for a fraud detection use case.
- Write a Hello World application in C#, C++, Go, Java, Node.js, PHP, Python, Ruby, or using the HBase client for Java.