Demo HBase

Connect to your cluster using SSH and run the HBase shell:

hbase shell

Create a new HBase table with two column families (cf1 and cf2) using the following statement:

create 'my-hbase-table', \
{NAME => 'cf1' , VERSIONS => 3}, \
{NAME => 'cf2'}

VERSIONS => 4 means we want to keep 4 versions maximum of this column.

The subsequent put statements insert data into a cell as defined by the row key (rowkey1 or rowkey2, in this case) and a column specified in the format <column_family> : <column_name>.

Unlike a traditional database, the columns are not defined at table design time and are not typed.

put 'my-hbase-table', 'rowkey1', 'cf1:fname', 'John'
put 'my-hbase-table', 'rowkey1', 'cf1:lname', 'Doe'
put 'my-hbase-table', 'rowkey2', 'cf1:fname', 'Jeffrey'
put 'my-hbase-table', 'rowkey2', 'cf1:lname', 'Aven'
put 'my-hbase-table', 'rowkey2', 'cf1:city', 'Hayward'
put 'my-hbase-table', 'rowkey2', 'cf2:photo', '<image>'

Enter the scan command to show the content of the table:

scan 'my-hbase-table'

The data inserted you see in the console can be conceptually viewed like this:

HBase supports sparsity. Not every column needs to exist in each row in a table and nulls are not stored.

Although HBase data is stored on HDFS, an immutable file system, HBase allows in-place updates to cells within HBase tables. It does this by creating a new version of the cell with a new time stamp if the column key already exists, and then a background compaction process collapses multiple files into a smaller number of larger files.

Update a cell:

put 'my-hbase-table', 'rowkey2', 'cf1:city', 'Melbourne'

Get the latest version of a cell:

get 'my-hbase-table', 'rowkey2', {COLUMNS => ['cf1:city']}

Get multiple versions of a cell:

get 'my-hbase-table', 'rowkey2', {COLUMNS => ['cf1:city'], VERSIONS => 2}

Log in to HUE. The HBase browser should now be available in the main menu.

We can now browse across HBase tables using in HUE:

To drop the table in HBase, type-in the following command in the HBase shell (NOTE: you need to disable a table prior to dropping the table in HBase):

disable 'my-hbase-table'
drop 'my-hbase-table'

results matching ""

    No results matching ""