After creating an E-MapReduce (EMR) cluster with the HBase service, connect to HBase Shell to read and write data using common shell commands.
Prerequisites
Before you begin, ensure that you have:
A DataServing cluster or custom cluster with the HBase service. See Create a cluster.
Connect to HBase
Log on to the cluster in SSH mode. See Log on to a cluster.
Start HBase Shell:
hbase shellThe shell displays basic usage tips, the HBase version, and the
hbase(main):001:0>prompt. Runhelpto see all available commands.
Common HBase Shell commands
Create a table
Use create to create a table. Specify the table name and at least one column family.
create 'table1', 'cf1'Write data
Use put to write a value to a specific cell. Each put call targets one cell, identified by a table name, row key, column, and value.
A column is written as <column-family>:<column-qualifier>. In the example below, cf1:q1 refers to column family cf1 and column qualifier q1. The three put calls write to two rows (r1, r2) across two columns (cf1:q1, cf1:q2).
put 'table1', 'r1', 'cf1:q1', 'v1'
put 'table1', 'r1', 'cf1:q2', 'v2'
put 'table1', 'r2', 'cf1:q1', 'v3'Scan a table
Use scan to read all rows that match a filter. The example below retrieves all cells in the cf1:q1 column of table1:
scan 'table1', {COLUMNS => 'cf1:q1'}Expected output:
ROW COLUMN+CELL
r1 column=cf1:q1, timestamp=2022-09-14T16:06:34.339, value=v1
r2 column=cf1:q1, timestamp=2022-09-14T16:06:36.615, value=v3
2 row(s)Get a single row or cell
Use get to read a single row or a specific cell. The example below retrieves the value of cf1:q1 in row r1:
get 'table1', 'r1', {COLUMNS => 'cf1:q1'}Expected output:
COLUMN CELL
cf1:q1 timestamp=2022-09-14T16:06:34.339, value=v1
1 row(s)Delete data
Delete a single cell
Use delete to remove the value of one cell. A cell is the intersection of a row and a column. The example below deletes the cf1:q1 cell in row r2:
delete 'table1', 'r2', 'cf1:q1'Delete all cells in a row
Use deleteall to remove all column values in a row. Add a column family name to limit the scope to that family. The example below deletes all data in row r1:
deleteall 'table1', 'r1'Drop a table
Dropping a table requires two steps: disable it first, then drop it.
Disable the table:
disable 'table1'Drop the table:
drop 'table1'
To bring a disabled table back online without dropping it, run enable:
enable 'table1'