Thursday, 2 May 2013

HBase:Delete table using HBaseAdmin API


In HBase, you can delete table using HBase Shell as follows:

hbase(main):002:0> disable 'mytable'
hbase(main):003:0> drop 'mytable'

However, you can also delete table using HBaseAdmin API as follows:

public class AdminDelete {
    
    public static void main(String[] args) throws IOException{
        
    Configuration conf = HBaseConfiguration.create();
    HBaseAdmin admin = null;
    
    try{
        admin=new HBaseAdmin(conf);
       }
    catch(Exception e)
       {
        e.printStackTrace();
        
       }
    
    
    if(admin.isTableAvailable("newtable")==true)
    {
    admin.disableTable("newtable");
    
    admin.deleteTable("newtable");
    System.out.println("Table Deleted");
    }
    else
    {
        System.out.println("NewTable does not exist");
    }
    
}
}

No comments:

Post a Comment