Low Orbit Flux Logo 2 F

How to List HBase Tables

Getting a list of tables is pretty straightforward in HBase. You can just use the list command from the hbase cli like this:


hbase(main):012:0 > list

This is great if you are setting up or administering a database. You might also want to do this programmatically from Java. Here is a bit of example code showing how you might do this.


import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.conf.Configuration;
import java.io.IOException;


public class Test1 {
    public static void main(String args[])throws MasterNotRunningException, IOException {

        HTableDescriptor[] td = new HBaseAdmin(HBaseConfiguration.create()).listTables();

        for ( int c=0; c < td.length; c++ ){
            System.out.println(td[c].getNameAsString());
        }
    }
}

This should be enough to get you started and cover most use cases that you might have when starting out with HBase. You likely have a lot more ahead of you but this should give you a taste of what you will be doing. It can be pretty easy with the right information.