HBase Shell & Commands – Usage & Starting HBase Shell
In this HBase tutorial, we will see HBase shell and its commands. Basically, to communicate with HBase, we use HBase Shell. However, there is much more to learn about HBase Shell. Also, we will learn how to start HBase Shell, to use it. Moreover, we will see some HBase Shell commands.
So let’s explore HBase Shell Commands.
What is HBase Shell?
In order to communicate with HBase, we use HBase Shell. Basically, to store the data, HBase uses the Hadoop File System, it has a master server as well as region servers and here the data storage will be in the form of regions (tables).
Hence, further, these regions will be split up and stored in region servers. In addition, the master server manages these region servers, and all these tasks take place on HDFS.
HBase Shell Usage
- Make sure to quote all names in HBase Shell, for example, Â table and column names.
- Also, commas delimit (determine the limits) command parameters.
- Just after entering a command to run it, type <RETURN>.
- In the creation and alteration of tables, we use dictionaries of configuration, they are Ruby Hashes. It looks like:
{‘key1’ => ‘value1’, ‘key2’ => ‘value2’, …}
              Especially, they are opened as well as closed with curly-braces.
- Moreover, by the ‘=>’ character combination, Key/values are delimited.
- Generally, Â here all the keys are predefined constants like NAME, VERSIONS, COMPRESSION, etc.
- However, there is no need to quote Constants. So, if we want to see a (messy) list of all constants in the environment, type ‘Object.constants’.
- If we need to enter binary keys or values or to use them it is important to use double-quote’d hexadecimal representation.
For example:
hbase> get 't1', "key\x03\x3f\xcd" hbase> get 't1', "key\003\023\011" hbase> put 't1', "test\xef\xff", 'f1:', "\x01\x33\x40"
Starting HBase Shell
By using the following command, we can connect to our running HBase via the shell:
$ ./bin/hbase shell HBase Shell; enter 'help<RETURN>' for the list of supported commands. Type "exit<RETURN>" to leave the HBase Shell Version: 0.90.0, r1001068, Fri MAY 24 13:55:42 PDT 2018 hbase(main):001:0>
Moreover, Â to see a listing of shell commands and options, type help and then <RETURN>.
Further, with a single column family named cf, create a table named test. By listing all tables, verify its creation and then insert some values.
hbase(main):003:0> create 'test', 'cf' 0 row(s) in 1.2200 seconds hbase(main):003:0> list 'test' .. 1 row(s) in 0.0550 seconds hbase(main):004:0> put 'test', 'row1', 'cf:a', 'value1' 0 row(s) in 0.0560 seconds hbase(main):005:0> put 'test', 'row2', 'cf:b', 'value2' 0 row(s) in 0.0370 seconds hbase(main):006:0> put 'test', 'row3', 'cf:c', 'value3' 0 row(s) in 0.0450 seconds
Here, we have inserted 3 values, one at a time. At row1, the first one is inserted, is column cf:a with a value of value1.
Now, by running a scan of the table, verify the data insert as follows:
hbase(main):007:0> scan 'test' ROW COLUMN+CELL row1 column=cf:a, timestamp=1288380727188, value=value1 row2 column=cf:b, timestamp=1288380738440, value=value2 row3 column=cf:c, timestamp=1288380747365, value=value3 3 row(s) in 0.0590 seconds
Moreover, to get a single row
hbase(main):008:0> get 'test', 'row1' COLUMN CELL cf:a timestamp=1288380727188, value=value1 1 row(s) in 0.0400 seconds
Further, to clean up all done above, disable and drop our table.
hbase(main):012:0> disable 'test' 0 row(s) in 1.0930 seconds hbase(main):013:0> drop 'test' 0 row(s) in 0.0770 seconds
Finally, by typing exit, exit the shell
hbase(main):014:0> exit
HBase Shell Commands
Here are some HBase Shell commands:
a. General Commands
i. Status
This command provides the status of HBase, like, the number of servers.
ii. version
It shows the version of HBase being used.
iii. table_help
This command provides help for table-reference commands.
iv. Whoami
It shows the information about the user.
b. Data Definition Language
The commands which operate on the tables in HBase, are Data Definition Language
i. Create
This command creates a table.
ii. List
It lists all the tables in HBase.
iii. Disable
This command disables a table.
iv. Is_disabled
Whereas, it verifies whether a table is disabled.
v. enable
This command enables a table.
vi. Is_enabled
However, it verifies whether a table is enabled or not.
vii. Describe
It shows the description of a table.
viii. Alter
This command alters a table.
ix. Exists
This one verifies whether a table exists or not.
x. Drop
This command drops a table from HBase.
xi. Drop_all
Whereas,  this command drops the tables matching the ‘regex’ given in the command.
xii. Java Admin API
Previously, to achieve DDL functionalities through programming, when the above commands were not there, Java provides an Admin API. Basically, HBaseAdmin and HTableDescriptor are the two important classes in this package which offers DDL functionalities, under org.apache.hadoop.hbase.client package.
c. Data Manipulation Language
Below we are discussing HBase Data Manipulation Language Command.
i. Put
In a particular table, this command puts a cell value at a specified column in a specified row.
ii. Get
We use Get command to fetch the contents of the row or a cell.
iii. Delete
In order to delete a cell value in a table, we use Delete command.
iv. Deleteall
However, to delete all the cells in a given row, we use Deleteall command.
v. scan
This command scans and returns the table data
vi. Count
To count and return the number of rows in a table, we use Count command.
vii. Truncate
Truncate command, disables, drops, and recreates a specified table.
viii. Java client API
Under org.apache.hadoop.hbase.client package, Java provides a client API to achieve DML functionalities, CRUD (Create Retrieve Update Delete) operations and more through programming, previously, when the above commands were not there.
So, this was all about HBase Shell Commands. Hope you like our explanation
Conclusion
Hence, in this HBase shell tutorial, we saw the concept of HBase Shell. Also, we learned 3 main HBase shell commands. Moreover, we discussed the start method in HBase. Still, if any doubt, ask in the comment tab.
Did we exceed your expectations?
If Yes, share your valuable feedback on Google