Put in Hbase using REST API(Stargate)
Hi Friends,
Today I am going to demonstrate simple example of putting data into hbase table using Stargate REST API.
In this example , I have a simple Employee json document which I want to store into one of the cell of hbase.
Here is my sample json documen.
{"Employee":{"Ename":"Sam","Eid":12}}
This sample contains employee name and employee ID. Instead of this json document i can use any other sample data which i want to store into hbase.
I created a table in hbase with table name testtable having column family as colfam1.
create 'testtable' , 'colfam1'
Now I have everything available to being with. Next step is to form you REST query and simply fire it insert data into hbase,
Here is sample example taken from https://wiki.apache.org/hadoop/Hbase/Stargate for inserting data into hbase.
Main job of each developer is to prepare --data information in above query. As we know , before inserting data into hbase we should first apply base64 encoding on data then we can put it into hbase,
I am putting row key 'row1' with column family 'colfam1:col1' into hbase having data as my json document.
Json format of --data information
In above json everything is base64 encode.
Encoding Data into base64 format
You can fire below command from shell and you will get base64 encoded data.
echo '{"Employee":{"Ename":"Sam","Eid":12}}' | tr -d "\n" | base64
Output : eyJFbXBsb3llZSI6eyJFbmFtZSI6IlNhbSIsIkVpZCI6MTJ9fQ==
Just to confirm , you have properly encoded data you can simply decode this informatiuon using below command
Decoding base64 information
echo eyJFbXBsb3llZSI6eyJFbmFtZSI6IlNhbSIsIkVpZCI6MTJ9fQ== | base64 -d
It will return you actuall input information.
Once everything is done just fire above mentioned curl command , and data will be inserted into hbase.
scan 'testtable'
hbase(main):009:0> scan 'testtable'
ROW COLUMN+CELL
row1 column=colfam1:col1, timestamp=1438079793144, value={"Employee":{"Ename":"Sam","Eid":12}}
Hope this helps. Cheers....!!!!!
Today I am going to demonstrate simple example of putting data into hbase table using Stargate REST API.
In this example , I have a simple Employee json document which I want to store into one of the cell of hbase.
Here is my sample json documen.
{"Employee":{"Ename":"Sam","Eid":12}}
This sample contains employee name and employee ID. Instead of this json document i can use any other sample data which i want to store into hbase.
I created a table in hbase with table name testtable having column family as colfam1.
create 'testtable' , 'colfam1'
Now I have everything available to being with. Next step is to form you REST query and simply fire it insert data into hbase,
Here is sample example taken from https://wiki.apache.org/hadoop/Hbase/Stargate for inserting data into hbase.
curl -H "Content-Type: text/xml" --data '[...]' http://localhost:8000/test/testrow/test:testcolumn
Main job of each developer is to prepare --data information in above query. As we know , before inserting data into hbase we should first apply base64 encoding on data then we can put it into hbase,
I am putting row key 'row1' with column family 'colfam1:col1' into hbase having data as my json document.
curl -v -X PUT -H "Content-Type: application/json" --data '{"Row":[{"key":"cm93MQ==", "Cell":[{"column":"Y29sZmFtMTpjb2wx", "$":"eyJFbXBsb3llZSI6eyJFbmFtZSI6IlNhbSIsIkVpZCI6MTJ9fQ=="}]}]}' http://hostname:8080/testtable/row1/colfam1:col1
Json format of --data information
In above json everything is base64 encode.
You can fire below command from shell and you will get base64 encoded data.
echo '{"Employee":{"Ename":"Sam","Eid":12}}' | tr -d "\n" | base64
Output : eyJFbXBsb3llZSI6eyJFbmFtZSI6IlNhbSIsIkVpZCI6MTJ9fQ==
Just to confirm , you have properly encoded data you can simply decode this informatiuon using below command
Decoding base64 information
echo eyJFbXBsb3llZSI6eyJFbmFtZSI6IlNhbSIsIkVpZCI6MTJ9fQ== | base64 -d
It will return you actuall input information.
Once everything is done just fire above mentioned curl command , and data will be inserted into hbase.
scan 'testtable'
hbase(main):009:0> scan 'testtable'
ROW COLUMN+CELL
row1 column=colfam1:col1, timestamp=1438079793144, value={"Employee":{"Ename":"Sam","Eid":12}}
Hope this helps. Cheers....!!!!!
I was searching for the right blog to get Hadoop updates to know what is happening in the Big Data industry. I found your blog where I can get a lot of new updates in storing and retrieving the data concept. Thank you admin I would like to share this blog with my friends also. Keep updating, waiting for your next article.
ReplyDeleteRegards
Best hadoop training institute in chennai
Big Data Hadoop Training in Chennai