HBase is a database built on top of the HDFS. HBase provides fast lookups for larger tables. The goal of the HBase project is to host very large tables — billions of rows multiplied by millions of columns — on clusters built with commodity hardware. HBase is an open-source, distributed, versioned, column-oriented storage.
Hbase consists of :
Table is a collection of rows.
Row is a collection of column families.
Column family is a collection of columns.
Example schema of the table in HBase.
Features of HBase :
- Integrates with Hadoop as source and destination.
- Available Java API .
- Hbase is Scalable.
- Supports automatic failure.
Use HBase where :
Your Application requires to have random, real-time read/write access to Big Data.
Let’s get started :-
- To use Hbase : Go to Shell/Terminal. Type command ” hbase shell “.
Something like this will open :-
2. To create table in Hbase use command : create ‘<table name>’ ,'<column family name>’ .
Here we have created the table with the name “employ” which has two column families (i) personal (ii) dep_details.
We use command “list” to show all tables in Hbase is equal to SQL “show tables” .
Remember : Unlike JAVA and SQL you don’t need semicolon “;” to end command.
3. Above command – created an empty table in Hbase. Now populate your tables with data USING command “put“. Just for reference you take command PUT similar to SQL command INSERT. In Hbase while inserting your data specify “ROW ID” – is unique value similar to PRIMARY KEY in SQL followed by “column family : column name ” and its “VALUE” i.e DATA.
put ‘ < ROW ID > ‘ , ‘ < COLUMN FAMILY NAME : COLUMN NAME >’ , ‘ < VALUE >’
raw input data for the table
4. To count the number of records in your table use command count i.e : count ‘ < table name > ‘.
but now you want to see whole data of your table use the command “scan” – scan ‘ < table name > ‘.
Entered something wrong data in your table, let’s erase it. To remove something from Hbase table use command “DELETE” – delete ‘ <table name>’, ‘<column family : column name>’ . Here we have employ data and employee name “lily” whose salary has been entered incorrectly.
We have one more similar command like SQL “truncate”, which will keep your table structure but delete all data. Use command truncate ‘<table name>’.
Don’t need even this table anymore, then remove it. First disable table using command – disable ‘<table name >’ and then drop your table using command – drop ‘<table name>’.
Happy Learning Apache Hbase !!