How To Insert Data in HBase Table

In our last blog post, I shared HBase create table, how to create a table in HBase.

In this post, I will be sharing how to insert data in HBase table. As we know, HBase is a column-oriented NoSQL database and stores data column wise.

Insert Data in HBase Table

Here I will be explaining How to create data in HBase table. Inserting data in HBase table can be done with the help of below three commands and methods-

put command,
add() method of Put class, and
put() method of HTable class
Using put command you can insert a record into the HBase table easily.

Insert Data in HBase Table Syntax

Here is the HBase Create data syntax. We will be using Put command to insert data into HBase table.

put ‘<table name>’,’row1’,’<columnfamily:colname>’,’<value>’

Example

Considering the example we considered in the HBase Create table example-

Id Name

Salary

101

John

100k

102 Chris

200k

No, we need to insert data in HBase table “employee” as per the records are shown in above table.

Put ‘employee’, ‘1’, ‘personaldata:Name’,’John’  –> This will insert the Name field for Row 1 in the employee table under PersonalData column family, “John”.

Similarly, you can insert other records as well like below-

Put ‘employee’, ‘1’, ‘careerdata:salary’, ‘100k’
Put ‘employee’, ‘2’, ‘personaldata: Name’, ‘Chris’
Put ‘employee’, ‘2’, ‘careerdata: Salary’, ‘200k’

With this, now you have all the records shown in above table.

Verify Records in HBase Table

Now as we have inserted the data in HBase table, employee, let’s validate whether the records are same what we expected.

You can use “scan” command to validate the data.

Syntax: 

scan ‘employee’

It will list you all the rows and records of the table ‘employee’.

Conclusion

This was all about How to Insert Data in HBase table. Inserting records in HBase table is easy and all you need is to use Put command for the same.

But with the Put command, you would be able to insert a record every time and if ever you need to do a bulk insert, you will find the issue.

In the next blog post, I will be telling you how to bulk insert into HBase table and HBase table Edit & Delete Operation.

 

Leave a Reply