HBase Commands

Use the help command to get a list of commands categorized by type. The command groups can be categorized as

  • General: These commands discover general information at the cluster level. Examples include status, whoami, and version.
  • DDL: These commands create, alter, and drop HBase tables. Examples include alter, create, describe, drop, enable, disable, and list.
  • DML: These commands add, modify, and delete data from HBase tables. Examples include get, put, delete, deleteall, get_counter, incr, put, scan, and truncate.
  • Tools: These commands perform maintenance of the HBase cluster. Examples include assign, close_region, compact, flush, hlog_roll, and major_compact.
  • Replication : These commands support adding and removing nodes in the cluster. Examples include add_peer, enable_peer, disable_peer, list_peers, start_replication, and   stop_replication.
  • Snapshot : These commands support taking snapshots of the HBase cluster for backup and recovery. Examples include snapshot, restore_snapshot, and list_snapshots.
  • Security: These commands assign security in HBase. Examples include grant and revoke.

HBase commands for data management are

  • Create a table – Use the create command to create a new table. You must specify the table name and the ColumnFamily name.

hbase(main):001:0> create ‘test’, ‘cf’

0 row(s) in 0.4170 seconds

=> Hbase::Table – test

  • List Information About your Table – Use the list command to

hbase(main):002:0> list ‘test’

TABLE

test

1 row(s) in 0.0180 seconds

=> [“test”]

  • Put data into your table – To put data into your table, use the put command.

hbase(main):003:0> put ‘test’, ‘row1’, ‘cf:a’, ‘value1’

0 row(s) in 0.0850 seconds

hbase(main):004:0> put ‘test’, ‘row2’, ‘cf:b’, ‘value2’

0 row(s) in 0.0110 seconds

hbase(main):005:0> put ‘test’, ‘row3’, ‘cf:c’, ‘value3’

0 row(s) in 0.0100 seconds

Here, we insert three values, one at a time. The first insert is at row1, column cf:a, with a value of value1. Columns in HBase are comprised of a column family prefix, cf in this example, followed by a colon and then a column qualifier suffix, a in this case.

  • Scan the table for all data at once – One of the ways to get data from HBase is to scan. Use the scan command to scan the table for data. You can limit your scan, but for now, all data is fetched.

hbase(main):006:0> scan ‘test’

ROW COLUMN+CELL

row1column=cf:a, timestamp=1421762485768, value=value1

row2column=cf:b, timestamp=1421762491785, value=value2

row3column=cf:c, timestamp=1421762496210, value=value3

3 row(s) in 0.0230 seconds

  • Get a single row of data – To get a single row of data at a time, use the get command.

hbase(main):007:0> get ‘test’, ‘row1’

COLUMN   CELL

cf:atimestamp=1421762485768, value=value1

1 row(s) in 0.0350 seconds

  • Disable a table – If you want to delete a table or change its settings, as well as in some other situations, you need to disable the table first, using the disable command. You can re-enable it using the enable command.

hbase(main):008:0> disable ‘test’

0 row(s) in 1.1820 seconds

hbase(main):009:0> enable ‘test’

0 row(s) in 0.1770 seconds

Disable the table again if you tested the enable command above:

hbase(main):010:0> disable ‘test’

0 row(s) in 1.1820 seconds

  • Drop the table – To drop (delete) a table, use the drop command.

hbase(main):011:0> drop ‘test’

0 row(s) in 0.1370 seconds

  • Exit the HBase Shell – To exit the HBase Shell and disconnect from your cluster, use the quit command. HBase is still running in the background.
  • Stop HBase – In the same way that the bin/start-hbase.sh script is provided to conveniently start all HBase daemons, the bin/stop-hbase.sh script stops them.

$ ./bin/stop-hbase.sh

stopping hbase………………..

$

After issuing the command, it can take several minutes for the processes to shut down. Use the jps to be sure that the HMaster and HRegionServer processes are shut down.

Get industry recognized certification – Contact us

Menu