Import CSV data into HBase using importtsv
One of the first cases we get to see with Hbase is loading it up with Data, most of the time we will have some sort of data in some format like CSV availalble and we would like to load it in Hbase, lets take a quick look on how does the procedure looks like:
lets examine our example data by looking at the simple structure that I have got for an industrial sensor
id, temp:in,temp:out,vibration,pressure:in,pressure:out
5842, 50, 30, 4, 240, 340
First of all make sure Hbase is started on your Sandbox as following
Creating the HBase Table
- Login as Root to the HDP Sandbox and and switch to the Hbase User
root> su - hbase
- Go to the Hbase Shell by typing
hbase> hbase shell
- Create the example table by typing
hbase(main):001:0> create 'sensor','temp','vibration','pressure'
- lets make sure the table was created and examine the structure by typing
hbase(main):001:0> list
- now, exit the shell by typing 'exit' and lets load some data
Loading the Data
- lets put the hbase.csv file in HDFS, you may SCP it first to the cluster by using the following command
macbook-ned> scp hbase.csv root@sandbox.hortonworks.com:/home/hbase
- now put in HDFS using the following command
hbase> hadoop dfs -copyFromLocal hbase.csv /tmp
- we shall now execute the Loadtsv statement as following
hbase> hbase org.apache.hadoop.hbase.mapreduce.ImportTsv -Dimporttsv.separator=, -Dimporttsv.columns="HBASE_ROW_KEY,id,temp:in,temp:out,vibration,pressure:in,pressure:out" sensor hdfs://sandbox.hortonworks.com:/tmp/hbase.csv
- once the mapreduce job is completed, return back to hbase shell and execute
hbase(main):001:0> scan sensor
- you should now see the data in the table
Remarks
- Importtsv statement generates massive amount of logs, so make sure you have enough space in /var/logs, its always better to have it mounted on a seperate directories in real cluster to avoid operational stop becuase of logs filling the partition.

