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.

Advertisements
Categories: HBase, Java

HBase installation on Ubuntu

September 11, 2012 Leave a comment

Steps to install HBase on Ubuntu Machine:

  1. Download latest Hbase  from http://hbase.apache.org/
  2. extract it to hbase
  3. Set JAVA_HOME variable in conf/hbase-env.sh
  4. Add hbase/bin to PATH variable
  5. go to hbase folder
  6. $bin/hbase  if it is giving some thing means hbase installed correctly

Start and Stop the HBase:

  1. Start the hbase : $bin/hbase start-hbase.sh
  2. 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:

  1. $bin/hbase shell run this command to enter into hbase shell
  2. To see list of tables created in hbase $bin/hbase list
  3. To create a table in hbase  $create ‘test’,’cf’
  4. Insert some values into the above created test $put ‘test’,’row1’,’cf:a’,’value1’
  5. To see the data $ scan ‘test’
  6. To get one row from the hbase table $ get ‘test’,’row1’.

To Delete Hbase table:

  1. after disabling we can able to drop it $disable ‘test’ and then $drop ‘test’

Hope it helps.

Thanks.

Categories: HBase