Apache HBase is a distributed column-oriented database built on top of the Hadoop file system. Use HBase when you need random, realtime read/write access to your Big Data. It provides a convenient interactive shell as well as a Java API.
Interactive Shell
You can start the HBase interactive shell using the command hbase shell. After entering this command, you will see the following output:
To exit the interactive shell, type exit or <ctrl+c>.
Create
The syntax to create a table from an HBase shell is shown below.
Note that in the HBase data model columns are grouped into "column families", which must be defined up front during table creation. These column families are stored together on disk. Because of this HBase is consided a column-oriented data store.
Let's create a table called hospital with two column families: id and value.
And it will give you the following output.
Update
List table(s)
Describe and alter table
The describe command returns the description of the table.
This shows some basic information for each column family. For example, the id column family has block size of 65536 and keeps at most 3 versions for each cell (distinguishable by timestamp).
We can alter the the table settings by using alter. But first we must disable the table.
Don't forget to re-enable after changing the setting.
Put data
Using the put command, you can insert rows into a table. The syntax is as follows:
For example, let's put a paitent-id record.
This puts the value patient-id-1 in row row1 and column patient (within the column family id).
Let's put some more records.
Read
Cluster status
To check the status of the cluster use the status command:
Table data
Using the scan command, you can view the table data.
If you only want to know the number of rows in a table, you can use:
The get command can be used to retrieve a single row of data at a time.
To retrieve the data in a particular column within a row we can use the following syntax:
Delete
Delete cell
You can delete a specific cell in a table by using the delete command
To delete all the cells in a row, use the deleteall command
Drop table
Using the drop command, you can delete a table. Before dropping a table, you must disable it.