Archive
Archive for the ‘HBase’ Category
Creating a HBase table through Java program
September 11, 2012
2 comments
To create a HBase table through Java program. We need to use HBaseConfiguration class
this is the main class which holds the configuration details about HBase.
then we have to add our hbase-site.xml to the HBaseConfiguration.
After preparing the configuration correctly pass this to HBaseAdmin. To specify the HBase table name HTableDescriptor will be used and
HColumnDescriptor is used for Column names.
After all set up is done call the createTable method of HBaseAdmin
import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.client.HBaseAdmin; public class HbaseTableCreator { public static void main(String[] args) throws Exception { HBaseConfiguration conf = new HBaseConfiguration(); conf.addResource("conf/hbase-site.xml"); conf.set("hbase.master","localhost:60000"); HBaseAdmin hbase = new HBaseAdmin(conf); HTableDescriptor desc = new HTableDescriptor("sample"); HColumnDescriptor meta = new HColumnDescriptor("samplecolumn1".getBytes()); HColumnDescriptor prefix = new HColumnDescriptor("samplecolumn2".getBytes()); desc.addFamily(meta); desc.addFamily(prefix); hbase.createTable(desc); } }
After successful running of the above program, check with hbase shell whether the table is created or not.
HBase installation on Ubuntu
September 11, 2012
Leave a comment
Steps to install HBase on Ubuntu Machine:
- Download latest Hbase from http://hbase.apache.org/
- extract it to hbase
- Set JAVA_HOME variable in conf/hbase-env.sh
- Add hbase/bin to PATH variable
- go to hbase folder
- $bin/hbase if it is giving some thing means hbase installed correctly
Start and Stop the HBase:
- Start the hbase : $bin/hbase start-hbase.sh
- Stop the hbase : $bin/hbase stop-hbase.sh // this will take time and remember stop the hadoop first and then stop the hbase.
HBase Shell Commands:
- $bin/hbase shell run this command to enter into hbase shell
- To see list of tables created in hbase $bin/hbase list
- To create a table in hbase $create ‘test’,’cf’
- Insert some values into the above created test $put ‘test’,’row1’,’cf:a’,’value1’
- To see the data $ scan ‘test’
- To get one row from the hbase table $ get ‘test’,’row1’.
To Delete Hbase table:
- after disabling we can able to drop it $disable ‘test’ and then $drop ‘test’
Hope it helps.
Thanks.
Categories: HBase