What is a table in Hbase

HBase listing table



is the command that is used to list all tables in HBase. Given below is the syntax of the List command. hbase (main): 001: 0> list

If you type this command and execute it in HBase prompt, it will display the list of all tables in HBase as shown below.

hbase (main): 001: 0> list TABLE emp

Here you can observe a table called emp.

Listing tables use Java API.

Follow the steps given below to get the list of tables from HBase using Java API.

Step 1

They have a method called listTables () in the class HBaseAdmin to get the list of all tables in HBase. This method returns an array of HTableDescriptor Objects.

// creating a configuration object Configuration conf = HBaseConfiguration.create (); // Creating HBaseAdmin object HBaseAdmin admin = new HBaseAdmin (conf); // Getting all the list of tables using HBaseAdmin object HTableDescriptor [] tableDescriptor = admin.listTables ();

step 2

You can get the length of the HTableDescriptor [] Array using the length variable from the HTableDescriptor Class. Get the names of the tables from this object with the help getNameAsString () Method. run the "for" loop using this and get the list of tables in HBase.

Since below the program will list all tables in HBase with Java API.

import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.MasterNotRunningException; import org.apache.hadoop.hbase.client.HBaseAdmin; public class ListTables {public static void main (String args []) throws MasterNotRunningException, IOException {// Instantiating a configuration class Configuration conf = HBaseConfiguration.create (); // Instantiating HBaseAdmin class HBaseAdmin admin = new HBaseAdmin (conf); // Getting all the list of tables using HBaseAdmin object HTableDescriptor [] tableDescriptor = admin.listTables (); // printing all the table names. for (int i = 0; i Compile and run the above program as shown below.

$ javac ListTables.java $ java ListTables

The output should be:

User emp